regex-lookarounds

Set together letters and numbers that are ordinal numbers

梦想与她 提交于 2020-03-02 09:14:31
问题 The purpose is to remove the space between the numbers and ordinal number abbreviation (st,rd,th,nd). For instance, the following numbers and abbreviations should be together to form 10th, 1st and 133rd: 10 th elementary 1 st grade 133 rd anniversary However, these other examples are not allowed to be set together: abc123 th 33333 rddccc 10 thetree 20 street For this purpose I have came out with the following regex: (?<=[0-9])+\s+(?=(st|nd|rd|th)\b) However it is setting together also the

Unmatch complete words if a negative lookahead is satisfied

让人想犯罪 __ 提交于 2020-02-15 10:15:48
问题 I need to match only those words which doesn't have special characters like @ and : . For example: git@github.com shouldn't match list should return a valid match show should also return a valid match I tried it using a negative lookahead \w+(?![@:]) But it matches gi out of git@github.com but it shouldn't match that too. 回答1: You may add \w to the lookahead: \w+(?![\w@:]) The equivalent is using a word boundary: \w+\b(?![@:]) Besides, you may consider adding a left-hand boundary to avoid

Regex for getting all digits in a string after a character

倖福魔咒の 提交于 2020-02-15 08:01:07
问题 I am trying to parse the following string and return all digits after the last square bracket: C9: Title of object (foo, bar) [ch1, CH12,c03,4] So the result should be: 1,12,03,4 The string and digits will change. The important thing is to get the digits after the '[' regardless of what character (if any) precede it. (I need this in python so no atomic groups either!) I have tried everything I can think of including: \[.*?(\d) = matches '1' only \[.*(\d) = matches '4' only \[*?(\d) = matches

Regex for getting all digits in a string after a character

北城余情 提交于 2020-02-15 08:00:29
问题 I am trying to parse the following string and return all digits after the last square bracket: C9: Title of object (foo, bar) [ch1, CH12,c03,4] So the result should be: 1,12,03,4 The string and digits will change. The important thing is to get the digits after the '[' regardless of what character (if any) precede it. (I need this in python so no atomic groups either!) I have tried everything I can think of including: \[.*?(\d) = matches '1' only \[.*(\d) = matches '4' only \[*?(\d) = matches

Regex in R: match collocates of node word

一个人想着一个人 提交于 2020-02-04 09:44:27
问题 I want to find collocates of a word in text strings. A word's collocates are those words that co-occur with it either preceding or following it. Here's a made-up example: GO <- c("This little sentence went on and on.", "It was going on for quite a while.", "In fact it has been going on for ages.", "It still goes on.", "It would go on even if it didn't.") Let's say I'm interested in the words collocating with the lemma GO including all the forms the verb 'go' can take, namely 'go', 'went',

Regular expressions: how to match numbers?

纵饮孤独 提交于 2020-01-25 07:12:08
问题 I want to use regular expressions to match numbers like these: 58158 60360 98198 That is in the format ABCAB . I use code below to match ABAB : (([\d]){1,}([\d]){1,})\1{1,} such as 5858 but how to match ABCAB(58158)? 回答1: For numbers in the format ABCAB : (\d)(\d)\d\1\2 This places no restriction on A=B=C . Use negative look-ahead for A!=B!=C : (\d)(?!\1)(\d)(?!\1|\2)\d\1\2 Edit: There is no boundary matching so 58158 will be matched in 36958158 : $num=36958158; preg_match('/(\d)(?!\1)(\d)(?!

Regular expressions: how to match numbers?

谁都会走 提交于 2020-01-25 07:12:06
问题 I want to use regular expressions to match numbers like these: 58158 60360 98198 That is in the format ABCAB . I use code below to match ABAB : (([\d]){1,}([\d]){1,})\1{1,} such as 5858 but how to match ABCAB(58158)? 回答1: For numbers in the format ABCAB : (\d)(\d)\d\1\2 This places no restriction on A=B=C . Use negative look-ahead for A!=B!=C : (\d)(?!\1)(\d)(?!\1|\2)\d\1\2 Edit: There is no boundary matching so 58158 will be matched in 36958158 : $num=36958158; preg_match('/(\d)(?!\1)(\d)(?!

Add Trailing Slash to URLs

五迷三道 提交于 2020-01-19 03:48:07
问题 There are quite a few results for add trailing slash .htaccess on Google, but all examples I found require the use of your domain name, as in this example: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !example.php RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301] My problem is that a hard-coded domain name will not work on my local development machine. Is there a way to add trailing slashes without explicitly

Regex, Match uppercase characters not between brackets

时间秒杀一切 提交于 2020-01-16 18:48:12
问题 In RegEx, I search a pattern that selects multiple uppercase characters (more than 1), that are not enclosed by curly braces. It should match: ABC AB XYZABC but not: {ABC} {AB} {XYZABC} 回答1: The below regex would match one or more uppercase letters only if it is not followed by a closing curly } bracket. ^[A-Z]+(?!.*?})$ DEMO OR You could use perl regex verbs, {.*?}(*SKIP)(*F)|[A-Z]+ DEMO 回答2: try this pattern [A-Z]+(?![^}{]*}) Demo 回答3: Try this pattern: {.*?}|([A-Z]+) Then test group1 if

How to match bold markdown if it isn't preceded with a backslash?

会有一股神秘感。 提交于 2020-01-16 12:02:36
问题 I'm looking to match bolded markdown. Here are some examples: qwer *asdf* zxcv matches *asdf* qwer*asdf*zxcv matches *asdf* qwer \*asdf* zxcv does not match *qwer* asdf zxcv matches *qwer* A negative look behind like this (?<!\\)\*(.*)\* works. Except there is no browser support in Firefox, so I cannot use it. Similarly, I can get very close with (^|[^\\])\*(.*)\* The issue is that there are two capture groups, and I need the index of the second capture group, and Javascript only returns the