regex

Perl regex with pipes

亡梦爱人 提交于 2021-02-05 06:09:47
问题 I'm not exactly a perl monk, so if you could help me digest what does this regex(if it is one) do? my $pathHere = "/some/path/to/file"; my $pathThere = "/some/path/"; $pathHere =~ s|$pathThere||; Perl is not exactly my everyday tool, so I am quite shy on knowledge - I guess it subs the match to the var value, but guessing is not the way to go - the pipes throw me off... Thanks 回答1: In Perl you'd normally use the / as a delimiter in the regexp. $pathHere =~ s/abc/def/; # replace 'abc' with

Perl regex with pipes

帅比萌擦擦* 提交于 2021-02-05 06:08:34
问题 I'm not exactly a perl monk, so if you could help me digest what does this regex(if it is one) do? my $pathHere = "/some/path/to/file"; my $pathThere = "/some/path/"; $pathHere =~ s|$pathThere||; Perl is not exactly my everyday tool, so I am quite shy on knowledge - I guess it subs the match to the var value, but guessing is not the way to go - the pipes throw me off... Thanks 回答1: In Perl you'd normally use the / as a delimiter in the regexp. $pathHere =~ s/abc/def/; # replace 'abc' with

Capturing repeating groups in GO

◇◆丶佛笑我妖孽 提交于 2021-02-05 06:05:12
问题 I'm trying to create a function that can parse strings which consist of an uppercase word followed by zero or more arguments which are encapsulated in double quotes. For example, each of the following lines: COPY "filename one" "filename two" REMOVE "filename" LIST "x" "y" "z" DISCONNECT The result should be a string (the command) followed by a string[] (the arguments inside the quotes). I created the following regular expression: re1, _ := regexp.Compile(`([A-Z]+)(?: "([^"]+)")*`) results :=

Capturing repeating groups in GO

主宰稳场 提交于 2021-02-05 06:05:01
问题 I'm trying to create a function that can parse strings which consist of an uppercase word followed by zero or more arguments which are encapsulated in double quotes. For example, each of the following lines: COPY "filename one" "filename two" REMOVE "filename" LIST "x" "y" "z" DISCONNECT The result should be a string (the command) followed by a string[] (the arguments inside the quotes). I created the following regular expression: re1, _ := regexp.Compile(`([A-Z]+)(?: "([^"]+)")*`) results :=

Regex in R: finding exact number

耗尽温柔 提交于 2021-02-05 06:03:22
问题 This is in R grep("AB22", c("AB22" ,"AB22","AB22" ,"AB22+3" ,"AB226AEM+1","AB22AEM+2") , value=T) gives all of them: "AB22","AB22", "AB22" ,"AB22+3" ,"AB226AEM+1" ,"AB22AEM+2" but, I want only "AB22","AB22","AB22" ,"AB22+3" ,AB22AEM+2" i.e. all the entries containing AB22 and not AB226 ot 2265...etc. Thanks 回答1: That's a job for word boundary anchors and/or a negative lookahead assertion: grep("\\bAB22(?!\\d)", c("AB22" ,"AB22","AB22" ,"AB22+3" ,"AB226AEM+1","AB22AEM+2") , value=T, perl=TRUE)

regex to match all words but AND, OR and NOT

落爺英雄遲暮 提交于 2021-02-05 06:01:19
问题 In my javascript app I have this random string: büert AND NOT 3454jhadf üasdfsdf OR technüology AND (bar OR bas) and i would like to match all words special chars and numbers besides the words AND , OR and NOT . I tried is this /(?!AND|OR|NOT)\b[\u00C0-\u017F\w\d]+/gi which results in ["büert", "3454jhadf", "asdfsdf", "technüology", "bar", "bas"] but this one does not match the ü or any other letter outside the a-z alphabet at the beginning or at the end of a word because of the \b word

Regex \b word boundary not works

扶醉桌前 提交于 2021-02-05 05:57:26
问题 In Android I have the next regexp \b(id)\b , In this query (i.e.) I want replace exactly the word 'id' : SELECT schedules.id as 'idreal' FROM schedules WHERE schedules.id = 12; Final query: SELECT schedules._id as 'idreal' FROM schedules WHERE schedules._id = 12; But it doesn't work, the \b is for word boundary, but it doesn't work. What i'm doing groing? This is my code: Matcher matcher = Pattern.compile("\b(id)\b").matcher(field); String query = matcher.replaceAll("_id"); Log.v(TAG, "Clean

Is there a way to apply regex modifiers for HTML5 input's pattern-attribute?

喜夏-厌秋 提交于 2021-02-05 05:56:12
问题 There is this snippet from the HTML specification, but either I do not understand the specification or it does not exactly say anything too informative regarding the regex-modifiers. 回答1: You should check this HTML5 pattern attribute documentation: If an input element has a pattern attribute specified, and the attribute's value, when compiled as a JavaScript regular expression with the global , ignoreCase , and multiline flags disabled (see ECMA262 Edition 5, sections 15.10.7.2 through 15.10

Latin Regex with symbols

帅比萌擦擦* 提交于 2021-02-05 05:51:27
问题 I need split a text and get only words, numbers and hyphenated composed-words. I need to get latin words also, then I used \p{L} , which gives me é, ú ü ã, and so forth. The example is: String myText = "Some latin text with symbols, ? 987 (A la pointe sud-est de l'île se dresse la cathédrale Notre-Dame qui fut lors de son achèvement en 1330 l'une des plus grandes cathédrales d'occident) : ! @ # $ % ^& * ( ) + - _ #$% " ' : ; > < / \ | , here some is wrong… * + () e -" Pattern pattern =

Perl regular expression to find a exact word

空扰寡人 提交于 2021-02-05 05:51:26
问题 I want to find the word sprintf in my code. What Perl regular expression should be used? There are some lines which have text like sprintf_private , which I want to exclude, but need just sprintf . 回答1: You must use \b at the words' border: /\bsprintf\b/ 回答2: If you want to find all occurrences of sprintf on lines that do not contain sprintf_private , you might use a pair of regexes: while( my $line = <DATA> ) { next if $line =~ m/\bsprintf_private\b/; while( $line =~ m/\bsprintf\b/g ) {