I am getting different results based on whether I precompile a regular expression:
>>> re.compile('mr', re.IGNORECASE).sub('', 'Mr Bean')
' Bean'
>>> re.sub('mr', '', 'Mr Bean', re.IGNORECASE)
'Mr Bean'
The Python documentation says Some of the functions are simplified versions of the full featured methods for compiled regular express...
I want to convert good bunch of url text.
from
CUSTOMER FAQS
HOW wE can HELP
PLANNING YOUR BUDGET
CUSTOMER CASE STUDIES
TENANT DISPUTES
EXIT STRATEGIES
USEFUL dOCUMENTS
USEFUL lINKS
to
customer-faqs
how-we-can-help
planning-your-budget
customer-case-studies
tenant-disputes
exit-strategies
useful-documents
useful-links
Is there any...
I have this web page where users can add smilies to their comments. And I want to limit the number of smilies per comment. The "system" works but I have some problems with the regex part.
I have my smilies defined in a config file like so:
$config['Smilies'] = Array (
// irrelevant stuff
'smilies' => Array (
':)' => 'smile....
Hi,
I am working on a math expression parser using regular expressions and I am trying to add support for parentheses.
My parser works like this:
function parse_expression(expression){
Find parenthetical expressions
Loop through parenthetical expressions, call parse_expression() on all of them
Replace parenthetical express...
Hello.
Good day.
My text file content below. tmp.txt (a very big size file)
constant fixup private AlarmFileName = <A "C:\\TMP\\ALARM.LOG"> /* A Format */
constant fixup ConfigAlarms = <U1 0> /* U1 Format */
constant fixup ConfigEvents = <U2 0> /* U2 Format */
My parse code below.
The code can't handle C:\\TMP...
suppose i am getting HTML text in my JavaScript function as
var TEMP= result.data;
where result.data='<p>BODY Article By Archie(Used By Story Tool)</p>';
i have done this:
var e = document.createElement("span");
e.innerHTML = TEMP;
var text = e.innerText;
var characterCount = tex...
Is there a nice table or a cheatsheet on the web that compares the sytax of emacs regex and PCRE?
That I have to remember to escape grouping parenthesis and braces and other differences when I'm using emacs regex, it's all confusing, a syntax comparison table would be good for minimizing confusion.
...
How do I display data from the beginning of a file until the first occurrence of a regular expression?
For example, if I have a file that contains:
One
Two
Three
Bravo
Four
Five
I want to start displaying the contents of the file starting at line 1 and stopping when I find the string "B*". So the output should look like this:
One
T...
I am a bit confused how to best use a Regular Expression and hope I can get some help I want to extract a URL value from an INI File as such:
[DEFAULT]
BASEURL=http://www.stackoverflow.com/
[InternetShortcut]
URL=http://www.stackoverflow.com/
So I can get the URL value as the only Match from the Regular expression - but I don't unders...
I have 20 or so characters that I need to replace with various other characters in a block of text. Is there a way to do this in a single regex, and what would this regex be? Or is there an easier way to do this in .NET?
For example, an excerpt from my mapping table is
œ => oe
ž => z
Ÿ => Y
À => A
Á => A
 => A
à => A
Ä => AE
...
Hi,
I have an array with words like
$arr = array("go", "walk", ...)
I would like to replace these words with links f they are matched in sentences. But it should be only if they match exactly (for example "walk" should match "Walk" or "walk!" but not also "walking")
And the replacement should be a simple link like: < a href='#walk' >...
(any symbol) _ (any symbol) _ (any symbol)
need as much as possible short regex patterns to extract symbols sequence between _, for ex:
abc123_abc12345ABC_123abc regex should extract - abc12345ABC
...
Hi, all.
I need to replace multiple whitespaces into a single whitespace (per iteration) in a document. Doesn't matter whether they are spaces, tabs or newlines, any combination of any kind of whitespace needs to be truncated to a single whitespace.
Let's say we have the string: "Hello,\t \t\n \t \n world", (where \t and \n repre...
I have the follow code:
string DB1 = DB1 = Regex.Match(contents, @"DB1=(?<DB1>[^\r\n]+)").Groups["DB1"].Value;
The code reads a file and looks for the following line:
DB1=Database\ABSER\ABSER
how can i modify the code that i have to exclude the 2nd \ABSER
I want my code to read only Database\ABSER , so essentially cut off the 2nd...
What benefits we can take using regex in xhtml css development?
any tools and useful regex commands?
...
Hi I have a difficult regex problem that I have tried and have a partial solution, but haven't gotten to work perfectly yet. Essentially, I have to parse a document that is in an outline format such as this:
1. HEY BUDDY
1.A. Your the best
1.A.1 And i know
1.A.2. this because
1.A.3 it is
1.A.4. the
1.A.5. truth i
1.A.6. tell ya.
1.B....
How do I split this comma+quote delimited String into a set of strings:
String test = "[\"String 1\",\"String, two\"]";
String[] embeddedStrings = test.split("<insert magic regex here>");
//note: It should also work for this string, with a space after the separating comma: "[\"String 1\", \"String, two\"]";
assertEquals("String 1"...
I have a bunch of URLs to parse in PHP, like this:
www.example.com/shopping
shopping.example.com
example.com/pages/shopping
for about 100 different pages (not just shopping - some are contact, some are directions, etc.). I have a seed set of data, which tells me where to look for the page names, like this:
www.example.com/[pagenam...
Is there some trick to do multi-line regular expression matches with <>, and loop over them? This example results in no matches when run on files with \n as the newline separator:
while (<> =~ m/\n./) {
print($.);
}
I need to know the line of the start of the match inside the while loop, as in the example.
The goal is to find all l...
Is there a built-in way to escape a string that will be used within/as a regular expression? E.g.
www.abc.com
The escaped version would be:
www\.abc\.com
I was going to use:
$string =~ s/[.*+?|()\[\]{}\\]/\\$&/g; # Escapes special regex chars
But I just wanted to make sure that there's not a cleaner built-in operation that I'm m...