I wonder if there is a way to use ungreedy matching in JavaScript? I tried the U modifer, but it doesn't seem to work.
I want to write a small BBCode parser in JavaScript, but without ungreedy matching it isn't possible (at least as far as I see it) to do something like this:
'[b]one[/b] two [b]three[/b]'.replace( /\[b\](.*)\[\/b\]/, '...
I have always written regexes like this
<A HREF="([^"]*)" TARGET="_blank">([^<]*)</A>
but I just learned about this lazy thing and that I can write it like this
<A HREF="(.*?)" TARGET="_blank">(.*?)</A>
is there any disadvantage to using this second approach? The regex is definitely more compact (even SO parses it better).
Edit: T...
I'm trying to replace every multiline import inside a Python source file.. So, the source goes like
from XXX import (
AAA,
BBB,
)
from YYY import (
CCC,
DDD,
EEE,
...
)
...other instructions...
and I'd like to get something like
from XXX import AAA, BBB
from YYY import CCC, DDD, EEE, ...
...other instructions...
...
I have a CMS that uses a syntax based on HTML comments to let the user insert flash video players, slideshows, and other 'hard' code that the user could not easily write.
The syntax for one FLV movies looks like this:
<!--PLAYER=filename.flv-->
I use this code:
$find_players = preg_match("/<!--PLAYER\=(.*)-->/si", $html_content, $mat...
preg_match('/(.*?)see below[^,\.<]*/s',$xml,$match);
echo $match[0];
the ouput is,which I think the non-greedy matching is not working:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<UserCredentials xmlns="http://jobg8.com/postadve...
demo:
$str = 'bcs >Hello >If see below!';
$repstr = preg_replace('/>[A-Z0-9].*?see below[^,\.<]*/','',$str);
echo $repstr;
What I want this tiny programme to output is "bcs >Hello ",but in fact it's only "bcs "
What's wrong with my pattern?
...
The domain of this question is scheduling operations on constrained hardware. The resolution of the result is the number of clock cycles the schedule fits within. The search space grows very rapidly where early decisions constrain future decisions and the total number of possible schedules grows rapidly and exponentially. A lot of the po...
Source: <prefix><content1><suffix1><prefix><content2><suffix2>
Engine: PCRE
RegEx1: (?<=<prefix>)(.*)(?=<suffix1>)
RegEx2: (?<=<prefix>)(.*)(?=<suffix2>)
Result1: <content1>
Result2: <content1><suffix1><prefix><content2>
The desired result for RegEx2 is just <content2> but it is obviously greedy.
How do I make RegEx2 ...
Hi,
I'd like to port a generic text processing tool, Texy!, from PHP to Java.
This tool does ungreedy matching everywhere, using preg_match_all("/.../U").
So I am looking for a library, which has some UNGREEDY flag.
I know I could use the .*? syntax, but there are really many regular expressions I would have to overwrite, and check th...
I am trying to extract all links that have /thumb/ in it within ""'s. Actually i only need to use the images src. I dont know if images will end with jpg or if there will be case sensitivity problems, etc. I really only care about the full link.
m = Regex.Match(page, @"""(.+?/thumbs/.+?)""");
//...
var thumbUrl = m.Groups[1].Value;
My...
Hi all,
I got the following text:
PRINT CONVERT(NVARCHAR,
CURRENT_TIMESTAMP, 111) + ' ' +
CONVERT(NVARCHAR, CURRENT_TIMESTAMP,
108)
+ ' -Test Mode : ' + (CASE WHEN @turbo_mode_ind = 1 THEN
'some text ''test'' some more text.'
ELSE 'an...
I'm trying to replace something like this:
NSSomeFunction(@"some var", @"another one")
With:
NSSomeOhterFunction(@"some var")
In Xcode. So these are source files...
I bet the regular expression will look something like this:
NSSomeFunction\((.*), .+\)
But I need this to be lazy. Otherwise .+) will match the last parenthesis occu...
I thought that by default my Regex would exhibit the greedy behavior that I want, but it is not in the following code:
Regex keywords = new Regex(@"in|int|into|internal|interface");
var targets = keywords.ToString().Split('|');
foreach (string t in targets)
{
Match match = keywords.Match(t);
Console.WriteLine("Matched {0,...
I have a string in a file a.txt
{moslate}alho{/moslate}otra{moslate}a{/moslate}
a need to get the string otra using sed.
With this regex
sed 's|{moslate}.*{/moslate}||g' a.txt
a get no output at all but when i add a ? to the regex
s|{moslate}.*?{/moslate}||g a.txt
(I've read somewhere that it makes the regex non-greedy) i get n...
Please help me to discover whether this is a bug in Python (2.6.5), in my competence at writing regexes, or in my understanding of pattern matching.
(I accept that a possible answer is "Upgrade your Python".)
I'm trying to parse a Yubikey token, allowing for the optional extras.
When I use this regex to match a token without any opti...
Hi,
How can I get all the matches in the following example:
// Only "abcd" is matched
MatchCollection greedyMatches = Regex.Matches("abcd", @"ab.*");
// Only "ab" is matched
MatchCollection lazyMatches = Regex.Matches("abcd", @"ab.*?");
// How can I get all matches: "ab", "abc", "abcd"
Thanks.
Peter
P.S.: I want to have the all...
I decided to, for fun, make something similar to markdown. With my small experiences with Regular Expressions in the past, I know how extremely powerful they are, so they will be what I need.
So, if I have this string:
Hello **bold** world
How can I use preg_replace to convert that to:
Hello <b>bold</b> world
I assume some...