I am not experienced with regex and lost whole day trying to match this:
343,SOME_URL
43555,SOME_URL
I need expression to match number and "," so I can cut it something like
343,SOME_URL to become only SOME_URL
Use regex:
[0-9]+, or \d+,
and replace it with empty string ("").
Related
I've a string SRE("Documents", with: "For boss") and I want to match string inside "" but without "".
I've come to regex \"([a-zA-Z0-9\s?]+) but in result I can see ["Documents, "For boss].
How the regex should looks like to exclude also first "?
Try "([^"]*)", where [^"] means matching a single character which is not ".
I have a regex which is \$[A-a]+[0-9]+ to match the strings like:
$A1 + $A10 to filter "$A1" and "$A10".
But if there is ":" before or after I don't want anything to be matched. Say, if the string is $A1:$A10. I don't want either $A1 or $A10 can be filtered.
How should I write the regex. I tried to use [^:] , which will be like:
[^:]\$[A-a]+[0-9]+[^:]
It seems string "$A1:$A10" works. (Nothing matched)
But then string "$A1+$A10" doesn't work. (Neither $A1 nor $A10 is matched)
You want zero-length lookahead and look behind patterns:
(?<!:)\$\a+\d+(?!:)
Demo
I have the following string:
_name=aVlTcWRjVG1YeDhucWdEbVFrN3pSOHZ5QTRjOEJZZmZUZXNIYW1PV2RGOWYrczBhVWRmdVJTMUxYazVBOE8zQ3JNMmNVKzJLM2JJTzFON3FiLzFHUE0xY0pkdz09LS1jbkkwaWoxUUl3YVhMMkhtZHpaOW13PT0"%"3D--57356371d167f"
I want to match everything between = and the end " (note there are other quotes after this so I can't just select the last ").
I tried using _name=(.*?)" but there are other quotes in the string as well. Is there a way to match the 3rd quote? I tried _name=(.*?)"{3} but the {3} matches for the quotes back to back, i.e. """
You can try it here
You can use this regex:
\b_name=(?:[^"]*"){3}
RegEx Demo
RegEx Details:
\b_name: Match full word _name:
=: Match a =
(?:[^"]*"){3}: Match 0 or more non-" characters followed by a ". Repeat this group 3 times.
If want to match everything between the first and the third(!) double quote (the third isn't necessarily the last, you told), you can use a pattern like this:
$string = '_name=foo"bar"test" more text"';
// This pattern will not include the last " (note the 2, not 3)
$pattern = '/_name=((.*?"){2}.*?)"/';
preg_match($pattern, $string, $m);
echo $m[1];
Output:
foo"bar"test
Original answer:
I'm not sure if I got you correctly, but it sounds like you want to perform a so called greedy match, meaning you want to match the string until the last " regardless whether the string contains multiple "s.
To perform a greedy match, just drop the ?, like this:
_name=(.*)"
You can try it here: https://regex101.com/r/uC5eO9/2
I'm so close to understanding regex. I'm a bit stumped, I thought i understood lazy and greedy.
Here is my current regex: <g_n><!\[CDATA\[([^]]+)(?=]]><\/g_n>)
My current regex makes:
<g_n><![CDATA[xxxxxxxxxx]]></g_n>
match to:
<g_n><![CDATA[xxxxxxxxxx
But I want to make it match like this:
xxxxxxxxxx
You want
<g_n><!\[CDATA\[(.*?)]]></g_n>
then if you want to replace it use
\1
in the replacement box
Your matching the whole string, the brackets around the .*? match all of that and put it in the \1 variable
So the match will be all of the string with \1 referring to what you want
To change the xxxxx
Regex :
(<g_n><![CDATA[)(?:.*?)(]]></g_n>)
Replacement
\1WHAT YOU WANT TO CHANGE TO\2
It looks like you need to add escape slashes to the two closing square brackets, as they are literals from the string you're parsing.
<g_n><!\[CDATA\[.*+?\]\]><\/g_n>
^ ^
Any square brackets not being escaped by backslashes will be treated as regex operational brackets, which in this case won't catch the input string.
EDIT, I think the +? is redundant.
\[.*\]\]> ...
should suffice, since .* means any character, any amount of times.
Tested with notepad++ 6.3.2:
find: (<g_n><!\[CDATA\[)([^]]+)(?=]]></g_n>)
replace: $1WhatYouWant
You can replace + by * in the pattern to match void CDATA:
<g_n><![CDATA[]]></g_n>
I have an ID that looks like this: prefix_my-awesome-slug_123
Now I would like to have a regular expression that removes the underscore and number on the end (_%d).
for perl like regex implementations this should do it:
s/_\d+$//
/_[0-9]+$/ - easy. Just replace the match with an empty string.