regex-group

regex c# optional group - should act greedy?

此生再无相见时 提交于 2019-12-24 02:48:36
问题 having regex ~like this: blablabla.+?(?:<a href="(http://.+?)" target="_blank">)? I want to capture an url if I find one... finds stuff but I don't get the link (capture is always empty). Now if I remove the question mark at the end like this blablabla.+?(?:<a href="(http://.+?)" target="_blank">) This will only match stuff that has the link at the end... it's 2.40 am... and I've got no ideas... --Edit-- sample input: blablabla asd 1234t535 <a href="http://google.com" target="_blank">

regex c# optional group - should act greedy?

北城余情 提交于 2019-12-24 02:48:11
问题 having regex ~like this: blablabla.+?(?:<a href="(http://.+?)" target="_blank">)? I want to capture an url if I find one... finds stuff but I don't get the link (capture is always empty). Now if I remove the question mark at the end like this blablabla.+?(?:<a href="(http://.+?)" target="_blank">) This will only match stuff that has the link at the end... it's 2.40 am... and I've got no ideas... --Edit-- sample input: blablabla asd 1234t535 <a href="http://google.com" target="_blank">

Force parsing optional groups

别来无恙 提交于 2019-12-23 16:54:53
问题 I'm trying to make a regex string that extracts data from report files. The tricky part is that I need this single regex string to match multiple report file content formats. I want the regex to always match even if some optional groups are not found. Take the following report files content ( Note : #2 is missing the "val2" part.): File #1: " -val1-test-val2-result-val3-done- " Expected Result: Val1 Group: test Val2 Group: result Val3 Group: done File #2: " -val1-test-val3-done- " Expected

Regex detect any repeated character but with optional whitespace between

夙愿已清 提交于 2019-12-23 16:09:34
问题 So currently I've got the following regex pattern, allowing me to detect any string containing 9 characters that are the same consecutively. /^.*(\S)\1{9,}.*$/ This works perfectly with a string like the following: this a tesssssssssst however I wish for it to also detect a string like this: this a tess sss ssssst (Same number of the repeated character, but with optional whitespace) Any ideas? 回答1: You need to put the backreference into a group and add an optional space into the group: ^.*(\S

Perl 6 capturing repeating matching groups separately?

狂风中的少年 提交于 2019-12-23 15:03:17
问题 I believe Perl 6 offers the capability of capturing repeating groups separately as opposed to earlier flavors where you could only capture the last group or the whole matched group string. Can someone please give a good example how to use this awesome feature of Perl 6? For e.g. I need to capture all the matching groups for this regex ((?:(?:(?:(?:")(?:[^"]*?)")|(?:(?<!")(?:[^"]*?)(?!")))(?<!\\)\|)*) How do I do that in Perl 6? 回答1: In general, if you quantify a capture, you simply get a list

Why sed doesn't print an optional group?

瘦欲@ 提交于 2019-12-23 09:48:18
问题 I have two strings, say foo_bar and foo_abc_bar . I would like to match both of them, and if the first one is matched I would like to emphasize it with = sign. So, my guess was: echo 'foo_abc_bar' | sed -r 's/(foo).*(abc)?.*(bar)/\1=\2=\3/g' > foo==bar or echo 'foo_abc_bar' | sed -r 's/(foo).*((abc)?).*(bar)/\1=\2=\3/g' > foo== But as output above shows none of them work. How can I specify an optional group that will match if the string contains it or just skip if not? 回答1: The solution: echo

extract substring using regex in groovy

前提是你 提交于 2019-12-23 06:44:34
问题 If I have the following pattern in some text: def articleContent = "<![CDATA[ Hellow World ]]>" I would like to extract the "Hellow World" part, so I use the following code to match it: def contentRegex = "<![CDATA[ /(.)*/ ]]>" def contentMatcher = ( articleContent =~ contentRegex ) println contentMatcher[0] However I keep getting a null pointer exception because the regex doesn't seem to be working, what would be the correct regex for "any peace of text", and how to collect it from a string?

Regex to match whatsapp chat log

99封情书 提交于 2019-12-22 17:58:01
问题 I've been trying to create Regex for WhatsApp chat log. So far I've been able to achieve this Click Here for the test link By creating the following Regex: (?P<datetime>\d{2}\/\d{2}\/\d{4},\s\d(?:\d)?:\d{2} [pa].m.)\s-\s(?P<name>[^:]*):(?P<message>.*) The problem with this regex is, it is not able to match big messages which span multiple lines with line breaks. You can see the issue in the link provided above. Help would be appreciated. Thank you. 回答1: There you go: ^ (?P<datetime>\d{2}/\d{2

Get the index of the group that matched in a regexp?

不羁岁月 提交于 2019-12-21 22:28:59
问题 I have a regexp: /(alpha)|(beta)|(gamma)/gi Some text to match against: Betamax. Digamma. Alphabet. Hebetation. The matches are: beta, gamma, alpha, beta The values I am looking would be: 1,2,0,1 ...can I ascertain the index of the group that matched in the regexp? 回答1: To access the groups, you will need to use .exec() repeatedly: var regex = /(alpha)|(beta)|(gamma)/gi, str = "Betamax. Digamma. Alphabet. Hebetation."; for (var nums = [], match; match = regex.exec(str); ) nums.push(match

Regular Expression in sed for multiple replacements in one statement

大憨熊 提交于 2019-12-21 03:10:56
问题 I want to sanitise some input and replace several characters with acceptable input, e.g. a Danish ' å ' with ' aa '. This is easily done using several statements, e.g. /æ/ae/ , /å/aa/ , /ø/oe/ , but due to tool limitations, I want to be able to do this in a single regular expression. I can catch all of the relevant cases ( /[(æ)(ø)(å)(Æ)(Ø)(Å)]/ ) but I replacement does not work as I want it to (but probably completely as intended): $ temp="RødgrØd med flæsk" $ echo $temp RødgrØd med flæsk $