regex

iOS - regex to match word boundary, including underscore

旧城冷巷雨未停 提交于 2021-02-10 13:16:05
问题 I have a regex that I'm trying to run to match a variety of search terms. For example: the search "old" should match: -> age_old -> old_age but not -> bold - as it's not at the start of the word To do this, I was using a word boundary. However, word boundary doesn't take into account underscores. As mentioned here, there are work arounds available in other languages. Unfortunately, with NSRegularExpression, this doesn't look possible. Is there any other way to get a word boundary to work? Or

Regex syntax in teradata

a 夏天 提交于 2021-02-10 13:09:24
问题 In functions like REGEXP_REPLACE , REGEXP_SIMILAR we need to mention the regular expression for matching a part of the string. Does the regex follow same syntax as that of regex in java or does Teradata have a separate syntax for regular expressions? 回答1: It's the same as PCRE (C, Java, PHP, Javascript). For example, let's say you have a bunch of emails and you want just the web domains from that you would use SELECT RegExp_Replace(email, '^.*@(.*)', '\1', 1, 0, 'i') FROM emails; You could

Python regex to pick all elements that don't match pattern

我的梦境 提交于 2021-02-10 12:49:10
问题 I asked a similar question yesterday Keep elements with pattern in pandas series without converting them to list and now I am faced with the opposite problem. I have a pandas dataframe: import pandas as pd df = pd.DataFrame(["Air type:1, Space kind:2, water, wood", "berries, something at the start:4, Space blu:3, somethingelse"], columns = ['A']) and I want to pick all elements that don't have a ":" in them. What I tried is the following regex which seems to be working: df['new'] = df.A.str

Regex Case Insensitive with input match

这一生的挚爱 提交于 2021-02-10 12:42:58
问题 I am trying to make validation for an html input by assigning via javascript a regex using the following code: $("#"+field.field_id).attr("data-validation",'custom'); $("#"+field.field_id).attr("data-validation-regexp",field.regex); If I set the regex to ^(Server (\d{1,2}))$ Then it works only with input 'Server ..' But i want the input Server to work with case insensitive. Like 'SERVER' or 'sErver'...... I tried to put ^(Server (\d{1,2}))$/i but it doesn't work. Any ideas ? 回答1: You can use:

Check if string contains an underscore in PHP

限于喜欢 提交于 2021-02-10 12:29:40
问题 I'm was wondering of a lightweight way of finding if a string contains an underscore (_). As a bonus if it was possible to have an if statement that not only checks for an underscore checks if the string is only two words connected. E.g I'm looking to check for strings like this "foo_bar". With no spaces, just the two words and an underscore. Any help would be great, Thanks! 回答1: $str = 'foo_bar'; if (preg_match('/^[a-z]+_[a-z]+$/i', $str)) { // contains an underscore and is two words } else

Bash regex with hyphen and dot

岁酱吖の 提交于 2021-02-10 12:23:06
问题 I'm trying to match hostname with regex. For some reason the following code fails. #!/bin/bash CONFIGURATION=m1si-ngxi-ddb01 #check configuration format TMP_CONFIGURATION=",${CONFIGURATION}" re=',[a-zA-Z0-9\-_\.]+' if ! [[ $TMP_CONFIGURATION =~ $re ]] then echo "configuration parttern mismatch." exit 1 fi Testing: [oracle@m1s-nyyy-db01 nir]$ vi a.sh [oracle@m1s-nyyy-db01 nir]$ 回答1: The pattern you have is failing due to "escaped" chars and the fact that - is not at the end/start of the

浅谈C#中HttpWebRequest与HttpWebResponse的使用方法

醉酒当歌 提交于 2021-02-10 12:05:21
1.第一招,根据URL地址获取网页信息 get方法 public static string GetUrltoHtml( string Url, string type) { try { System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url); // Get the response instance. System.Net.WebResponse wResp = wReq.GetResponse(); System.IO.Stream respStream = wResp.GetResponseStream(); // Dim reader As StreamReader = New StreamReader(respStream) using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type))) { return reader.ReadToEnd(); } } catch (System.Exception ex) { // errorMsg = ex.Message; } return "" ; } View Code post方法 1 /// <summary

Regular Expression That Contains At Least One Of Each

烈酒焚心 提交于 2021-02-10 09:29:49
问题 I'm trying to capitalize "words" that have at least one number, letter, and special character such as a period or dash. Things like: 3370.01b , 6510.01.b , m-5510.30 , and drm-2013-c-004914 . I don't want it to match things like: hello , sk8 , and mixed-up I'm trying to use lookaheads, as suggested, but I can't get it to match anything. $output = preg_replace_callback('/\b(?=.*[0-9]+)(?=.*[a-z]+)(?=.*[\.-]+)\b/i', function($matches){return strtoupper($matches[0]);}, $input); 回答1: You can use

JavaScript regular expression to replace a sequence of chars

时光怂恿深爱的人放手 提交于 2021-02-10 08:43:07
问题 I want to replace all spaces in the beginning and the end of a string with a underscore in this specific situation: var a = ' ## ## # '; console.log(myReplace(a)); // prints ___## ## #__ i.e.: all the spaces in the beginning of the string before the first # and all the spaces after the last #, everything else (including spaces in the middle of the string) remains untouched. My initial thinking was to use two Reg Exp, one for each part of the problem. However, I couldn't get the first one and

JavaScript regular expression to replace a sequence of chars

久未见 提交于 2021-02-10 08:42:15
问题 I want to replace all spaces in the beginning and the end of a string with a underscore in this specific situation: var a = ' ## ## # '; console.log(myReplace(a)); // prints ___## ## #__ i.e.: all the spaces in the beginning of the string before the first # and all the spaces after the last #, everything else (including spaces in the middle of the string) remains untouched. My initial thinking was to use two Reg Exp, one for each part of the problem. However, I couldn't get the first one and