I have this regex: link
((?<=<li><a href="\/bi-platform.*\/">bi-platform.*<\/a><\/li>).*)
That is matching the first occurrence of
<li>bi-platform940</li>DONTWANTTHIS
<li>bi-platform887</li>DONTWANTTHIS
<li>bi-platform953</li>WANTTHIS!!
iiiiioioioioi
kllkmkmkm
lçm
How can I match the last occurrence? (WANTTHIS!!) (I don't want to match this word it can be something else)
Try:
.*bi-platform\d+<\/a><\/li>(.*?)\n
Regex demo.
EDIT: To replace the word: https://regex101.com/r/En0r5T/1
Turning on "global" flag is not what I want. Yes I want the word after the last </li>
You can follow this link: https://regexr.com/78b8j
Related
I have this pattern
.*;\/wp-content\/uploads\/(.*)\.
and this in string format
<div class="js-aem-gallery" data-images="{"omniture":{"type":"","hasImpression":false},"slides":[{"title":"","omniture":null,"description":"","path":"/wp-content/uploads/auto-shows/frankfurt/2017/2019-porsche-cayenne/02-2019-porsche-cayenne-turbo-NP.jpg","thumbnail":"/wp-content/uploads/auto-shows/frankfurt/2017/2019-porsche-cayenne/02-2019-porsche-cayenne-turbo-NP.jpg?w=320&h=240&crop=1"},{"title":"","omniture":null,"description":"","path":"/wp-content/uploads/make/porsche/cayenne/2019/oem/21-2019-porsche-cayenne.jpg","thumbnail":"/wp-content/uploads/make/porsche/cayenne/2019/oem/21-2019-porsche-cayenne.jpg?w=320&h=240&crop=1"},{"title":"","omniture":null,"description":"","path":"/wp-content/uploads/make/porsche/cayenne/2019/oem/23-2019-porsche-cayenne.jpg","thumbnail":"/wp-content/uploads/make/porsche/cayenne/2019/oem/23-2019-porsche-cayenne.jpg?w=320&h=240&crop=1"},{"title":"","omniture":null,"description":"","path":"/wp-content/uploads/make/porsche/cayenne/2019/oem/30-2019-porsche-cayenne.jpg","thumbnail":"/wp-content/uploads/make/porsche/cayenne/2019/oem/30-2019-porsche-cayenne.jpg?w=320&h=240&crop=1"}]}"></div>
I want to match all the occurrences that appear between ;/wp-content/uploads/ and .jpg
I tried to match this, but it shows last group only.
I am new to regex, so please correct me with the implementation here, thank you.
You can make use of lookarounds to do clean extractions:
(?<=;\/wp-content\/uploads\/)(.*?)(?=\.jpg)
https://regex101.com/r/vzJ0FU/1
I have text:
test: [ABCD]
test: foobar
test: [ABCD]
And I've wrote this regex:
test:\s+(?!\[ABCD)
So basicaly I want to find any occurence where test: is NOT followed by [ABCD and there can be any amount of whitespace between the two.
So for the first two examples it works as intended but I have problem with the third one: it looks like because of this part: (?!\[ABCD) the \s+ is not matching last space if there are more than one. Why is that and how to solve it? I want to third example bahave just like frist one. Screenshot from regex101 to illustrate the issue:
You get the last match, as \s+ can backtrack one step to make sure the last assertion is true.
There is no language listed, but is possessive quantifiers are supported, you can also use
test:\s++(?!\[ABCD)
See a regex demo.
You need the lookahead before the match with an anchor:
/^(?!test:\s+\[ABCD\]).*/
Demo
You have one good answer to match the entire line if it follows the criteria, but based on this:
I want to find any occurence where "test:" is NOT followed by "[ABCD" and there can be any amount of whitespace between the two.
If you want to only match the "test:" part, you can just move the whitespace character into the negative look-ahead on what you have.
test:(?!\s+\[ABCD)
Screenshot from regex101 using your example phrases:
My text is:
120 something 130 somethingElse Paris
My goal is to capture 130 somethingElse Paris which means only the last occurrence of number BEFORE Paris
I tried:
\d+.*Paris
But this captures the WHOLE string (from first occurrence of digit)
The rule is:
Capture everything before Paris until first occurrence of digit is found.
Any clue ?
regards
Try this regex:
/(\d+[^\d]*Paris)/gi
http://jsfiddle.net/rooseve/XDgxL/
less tracebacks and without relying on greediness:
\d+[^0-9]*Paris
for last occurrence
^code:[ ]([0-9a-f-]+)(?:(?!^code:[ ])[\s\S])*Paris
you have to customize with your text.
Please refer this:
Regex match everything from the last occurrence of either keyword
Match from last occurrence using regex in perl
RegExp: Last occurence of pattern that occurs before another pattern
Regex get last occurrence of the pattern
You should add a ? after the * to make it un-greedy. Like this:
\d+.*?Paris
You can use this pattern:
(\d+\D*?)+Paris
other occurences of the capturing group are overwritten by the last.
The lazy quantifier *? is used to force the pattern to stop at the first word "Paris". Otherwise, in a string with more than one word "Paris", the pattern will return the last group after the last word "Paris" with a greedy quantifier.
i have a problem here, i have the following string
#Novriiiiii yauda busana muslim #nencor haha. wa'alaikumsalam noperi☺
then i use this regex pattern to select all the string
\w+
however, i need to to select all the string except the word which prefixed with # like #Novriiiiii or #nencor which means, we have to exclude the #word ones
how do i do that ?
ps. i am using regexpal to compile the regex. and i want to apply the regex pattern into yahoo pipes regex. thank you
You can use a negative lookbehind so that if a word is preceded by # it is excluded. You also need a word boundary before the word or else the lookbehind will only affect the first character.
(?<!#)\b\w+
http://rubular.com/r/ONEl70Am5Q
Does this suit your needs?
http://rubular.com/r/uuXvNrUiGJ
[^#\w+]\w+
This would sole your problem indeed:
[^#\w+][\w.]+
Check this link: http://regexr.com?34tq7
If you cannot use a negative lookbehind as other answers have already suggested, here's a workaround.
\w already doesn't match the # character, so you'd want something like this:
[^#]\w+
But this will (a) not work at the beginning of the string, and (b) include the character before the word in the match. To fix (a), we can do:
(^|[^#])\w+
To fix (b), we parenthesize the part we want:
(^|[^#])(\w+)
Then use $2 or \2 (depending on regex dialect) to refer to the matched word.
Another option is to include the # symbol in the word:
[\w#]+
And then add another step in your Pipe to filter out all words that start with an #.
A way to do that is to remove words that you don't want. Example:
find: #\w+
replace: empty string
you obtain the text without #abcdef words.
I am trying to get the first word in the line that matches the whole word 'number'. But I am only interested where whole word 'number' is matched and is preceded by a tab.
For example if following is the text:
tin identification number 4/10/2007 LB
num number 9/27/2006 PAT
I want to get back num
Regex I have is:
match whole word: \bnumber\b
if above is found then get first word: ([^\s]*)
I think I need modification in match whole word regex so that it only matches when whole word is preceded by a tab
This answer depends a bit on your regex engine as they can have different representations for tab. In the .Net regex engine though it would look like ...
\tnumber
try lookahead:
([^\s]+)(?=.*\tnumber)
(?:(\t([^\t ]*)))