regex

Reasons for not using `\s` and `\S`

試著忘記壹切 提交于 2021-02-08 10:59:56
问题 In GNU sed answers using the regular expression extensions \s which matches whitespace caracters and its dual \S which matches non-whitespace characters, seem to be shied from. Why is this? 回答1: They're GNU-only and so non-portable to other seds, that's all. Just wrt matching white space and use of -E (idk about the rest), the example you referenced would work with OSX/BSD sed or GNU sed as written, but if you used \s instead of [ \t] then it'd stop working in OSX/BSD sed. Personally I'd have

Text Editor(Sublime Text, Geany, Notepad++ etc.) Regex to remove all parameters from URL string except one parameter-value

点点圈 提交于 2021-02-08 10:46:28
问题 I am not very familiar with advanced matching patterns in Regex. I have some Google Search URLs which I need to clean up without having to hold Backspace key for 5 seconds to remove unnecessary parameters from the URL. Let's say I have this URL(could many different URLs following patterns like below): https://www.google.com/search?source=hp&ei=Ne4pXpSIHIW_9QOD-rmADw&q=laravel+crud+generator&oq=laravel+crud+generator&gs_l=psy-ab.3..0l8.1294.6845..7289...1.0..0.307.3888.0j20j2j1......0....1.

Using regex to restrict input in textbox [duplicate]

房东的猫 提交于 2021-02-08 10:44:20
问题 This question already has answers here : HTML input that takes only numbers and the + symbol (7 answers) Closed 3 years ago . /^+{0,1}(?:\d\s?){11,13}$/ this regex allows + at first place only and numbers only... on keypress I want user should only be able to type + at first and digits that what above regex validates But code always goes to if part..why regex not working in this scenario function ValidatePhone(phone) { var expr = /^\+?(?:\d\s?){11,13}$/; return expr.test(phone); } var

Using regex to restrict input in textbox [duplicate]

你。 提交于 2021-02-08 10:43:01
问题 This question already has answers here : HTML input that takes only numbers and the + symbol (7 answers) Closed 3 years ago . /^+{0,1}(?:\d\s?){11,13}$/ this regex allows + at first place only and numbers only... on keypress I want user should only be able to type + at first and digits that what above regex validates But code always goes to if part..why regex not working in this scenario function ValidatePhone(phone) { var expr = /^\+?(?:\d\s?){11,13}$/; return expr.test(phone); } var

Find number and replace + 1

拟墨画扇 提交于 2021-02-08 10:33:36
问题 I have a large file with a list of objects that have an incrementing page # ie [ {page: 1}, {page: 2}, {page: 3} ] I can find each instance of page: # with page: (\d) in vscode's ctrl+f finder. How would I replace each of these numbers with # + 1? 回答1: It's not possible to perform arithmetic with regex. I use LINQPad to execute these small kind of scripts. An example of how I would do it is in the c# program below. void Main() { var basePath = @"C:\"; // Get all files with extension .cs in

Escaping double quotation marks in sed

依然范特西╮ 提交于 2021-02-08 10:28:24
问题 Creating a search and replace function for my application, I am running a test scenario with 3 files, array tscript test I am trying to escape double quotation marks but it wont work script file contains variableName=$1 sed "s#data\-field\=\"${variableName}\.name\"#data\-field\=${variableName}\.name data\-type\=dropdown data\-dropdown\-type\=${variableName}#g" test test file contains data-field=“fee_category.name” data-field=“tax_type.name” array file contains fee_category tax_type There is

RegEx MM DD YYYY to YYYY MM DD

∥☆過路亽.° 提交于 2021-02-08 10:16:33
问题 I am new here and almost as new to RegEx. I am trying to use a RegEx expression to convert dates in a string in this format 05-18-16 or 5-18-16 or 05 18 16 or 5 18 16 to YYYY MM DD format. Note the dates in the string can be YY or YYYY. I have the "Find" expression working, but having trouble with the replacement. I found some code on this site that I thought would work, but the result is always "1900 1 31" and not 2016 05 18" Sub StackExPost() Dim strIn As String, strReturn As String strIn =

C# regex check string contains html

喜你入骨 提交于 2021-02-08 10:10:53
问题 I'm using following regex pattern to check a string contains html. string input = "<a href=\"www.google.com\">test</a>"; const string pattern = "</?\\w+((\\s+\\w+(\\s*=\\s*(?:\".*?\"|'.*?'|[^'\">\\s]+))?)+\\s*|\\s*)/?>"; Regex reg = new Regex(pattern); var matches = reg.Matches(input); It works fine but if string text value contains < or > characters it returns true too, but it shouldn't. For example the following is not considered an HTML tag in our system. string input = "<test>"; How can I

r regex Lookbehind Lookahead issue

故事扮演 提交于 2021-02-08 10:06:42
问题 I try to extract passages like 44.11.36.00-1 (precisely, nn.nn.nn.nn-n , where n stands for any number from 0-9) from text in R. I want to extract passages if they are "sticked" to non-number marks: 44.11.36.00-1 extracted from nsfghstighsl44.11.36.00-1vsdfgh is OK 44.11.36.00-1 extracted from fa0044.11.36.00-1000 is NOT I have read that str_extract_all is not working with Lookbehind and Lookahead expressions, so I sadly came back to grep , but cannot deal with it: > pattern1 <- "(?<![0-9]{1}

Extract word from string Using python regex

戏子无情 提交于 2021-02-08 09:56:55
问题 I want to extract a Model Number from string , /dev/sda: ATA device, with non-removable media Model Number: ST500DM002-1BD142 Serial Number: W2AQHKME Firmware Revision: KC45 Transport: Serial, SATA Rev 3.0 Regex I wrote, re.search("Model Number:(\s+[\w+^\w|d]\n\t*)", str) But issue is, its not matching any special characters (non ascii) in string str Python 2.6 Note: String can be combination any characters/digits (including special) 回答1: Your regex would be, Model Number:\s*([\w-]+) Python