Situation:
text: a string
R: a regex that matches part of the string. This might be expensive to calculate.
I want to both delete the R-matches from the text, and see what they actually contain. Currently, I do this like:
import re
ab_re = re.compile("[ab]")
text="abcdedfe falijbijie bbbb laifsjelifjl"
ab_re.findall(text)
# ['...
I'd like to improve my regex knowledge. Are there any exercises/tools that you wolud recommend?
...
I have the following C# which simply replaces parts of the input string that look like EQUIP:19d005 into URLs, like this:
input = Regex.Replace(input, @"(EQUIP:)(\S+)", @"<a title=""View equipment item $2"" href=""/EquipmentDisplay.asp?eqnum=$2"">$1$2</a>", RegexOptions.IgnoreCase);
The HTML ends up looking like this.
<a title="View ...
How would you go about creating a random alpha-numeric string that matches a certain regular expression?
This is specifically for creating initial passwords that fulfill regular password requirements.
...
I'm trying to write a regex to replace all spaces that are not included in quotes so something like this:
a = 4, b = 2, c = "space here"
would return this:
a=4,b=2,c="space here"
I spent some time searching this site and I found a similar q/a ( http://stackoverflow.com/questions/79968/split-a-string-by-spaces-in-python#80449 ) that w...
I've been looking for a simple regex for URL's, does anybody have one handy that works well? I didn't find one with the zend framework validation classes and have seen several implementations.
Thanks
...
How can I replace multiple spaces in a string with only one space in C#?
Example "1 2 3 4 5" would be : "1 2 3 4 5"?
...
I've created the following regex pattern in an attempt to match a string 6 characters in length ending in either "PRI" or "SEC", unless the string = "SIGSEC". For example, I want to match ABCPRI, XYZPRI, ABCSEC and XYZSEC, but not SIGSEC.
(\w{3}PRI$|[^SIG].*SEC$)
It is very close and sort of works (if I pass in "SINSEC", it returns a ...
I'm pretty new to regular expressions.
I have a requirement to replace spaces in a piece of multi-line text. The replacement rules are these:
Replace all spaces at start-of-line with a non-breaking space ( )
Replace any instance of repeated spaces (more than one space together) with the same number of non-breaking-spaces
Single s...
I would like to match the time (10.00) from a string with the date and time ("21.01.08 10.00"). I'm using the following regular expression:
new RegExp("\\b[0-9]{1,2}\\.[0-9]{1,2}\\b" "g");
But this matches 21.01 from 21.01.08 and 10.00.
I'm using PCRE as my regualar expression engine.
Update:
I'm sorry, i should have more been mor...
I have code similar to this filtering entries in an Array of Objects:
var filterRegex = new RegExp(".*blah.*","ig");
if (filterRegex.test(events[i].thing) && events[i].show) {
console.log("SUCCESS: filtering thing " + i + " " + events[i].thing);
events[i].show = false;
numevents--;
}
I get inconsistent results with this if...
I'm looking for a regex that can pull out quoted sections in a string, both single and double quotes.
IE:
"This is 'an example', \"of an input string\""
Matches:
an example
of an input string
I wrote up this:
[\"|'][A-Za-z0-9\\W]+[\"|']
It works but does anyone see any flaws with it?
EDIT: The main issue I see is that it can...
Is there a way in PHP to compile a regular expression, so that it can then be compared to multiple strings without repeating the compilation process? Other major languages can do this -- Java, C#, Python, Javascript, etc.
...
I'm sure this one is easy but I've tried a ton of variations and still cant match what I need. The thing is being too greedy and I cant get it to stop being greedy.
Given the text:
test=this=that=more text follows
I want to just select:
test=
I've tried the following regex
(\S+)=(\S.*)
(\S+)?=
[^=]{1}
...
Thanks all.
...
I have this regex I built and tested in regex buddy.
"_ [ 0-9]{10}+ {1}+[ 0-9]{10}+ {2}+[ 0-9]{6}+ {2}[ 0-9]{2}"
When I use this in .Net C#
I receive the exception
"parsing \"_ [ 0-9]{10}+ +[ 0-9]{10}+ +[ 0-9]{6}+ [ 0-9]{2}\" - Nested quantifier +."
What does this error mean? Apparently .net doesn't like the expression.
Here is ...
What do I use to search for multiple words in a string? I would like the logical operation to be AND so that all the words are in the string somewhere. I have a bunch of nonsense paragraphs and one plain English paragraph, and I'd like to narrow it down by specifying a couple common words like, "the" and "and", but would like it match ...
I have seen many examples, with many 'no, you missed something' comments. What is the right way to match an e-mail address?
For Sanity sake, only fully-qualified domain names, no @localhost allowed. (or, both ways)
Subdomains must be allowed ([email protected])
...
No extracted data output to data2.txt? What goes wrong to the code?
MyFile.txt
ex1,fx2,xx1
mm1,nn2,gg3
EX1,hh2,ff7
This is my desired output in data2.txt:
ex1,fx2,xx1
EX1,hh2,ff7
#! /DATA/PLUG/pvelasco/Softwares/PERLINUX/bin/perl -w
my $infile ='My1.txt';
my $outfile ='data2.txt';
open IN, '<', $infile or die "Cant open $in...
There are a number of email regexp questions popping up here, and I'm honestly baffled why people are using these insanely obtuse matching expressions rather than a very simple parser that splits the email up into the name and domain tokens, and then validates those against the valid characters allowed for name (there's no further check ...
What I want to do is check for duplicated words right next to each other but even if there is punctuation in between.
For example:
Vivamus Vivamus diam, diam, Vivamus Vivamus diam, diam Vivamus
there should be 4 distinct hits here.
I can't figure out why this isn't working; can someone explain why and show me what the correct code s...