regex

Storing regular expressions in MySQL database table and maching against them

I have a very interesting task, which I don't know how to implement. I need to store many regular expressions in a database table, and need to be able to find which of them matches the given string. For example: id | regexp ---|------------- 1 | ^hello world$ 2 | ^I have [0-9] flowers& 3 | ^some other regexp$ 4 | ^and another (o...

Regex for alphanumeric

I've this PHP regular expression: $username = preg_replace('/[^a-z0-9]/i', '', $username); It allows only A-Z and 0-9. How can I allow ., - and _ as well? ...

Only keep the legal chars in a text using a .NET Regex

I have a list of legal characters and I want to remove all others chars from text. // my legal chars. a-Z, numbers, space, _, - and percentage string legalChars = "[\p{L}\p{Nd}_\- %]*" string text = "[update], Text with {illegal} chars such as: !? {}"; I do find a lot of examples for removing illegal chars. I want to do the...

ereg_replace missing square brackets?

Hey I have the following code that should strip all non alphanumerics (excluding hyphens) from some text. It does however miss square brackets somehow? ereg_replace('[^A-z0-9-]', '', strtolower(str_replace(' ','-',$title))) Can anyone advise? ...

python parsing url after string

I want to extract a string from a url (link). That string is in a <h3></h3> tag. link = http://www.test.com/page.html Content of link: <h3>Text here</h3> What would be an elegant way to first get the content/sourcecode of page.html and then exctract the link? Thanks! ...

how to use a regex to search backwards effectively?

hi, i'm searching forward in an array of strings with a regex, like this: for (int j = line; j < lines.length; j++) { if (lines[j] == null || lines[j].isEmpty()) { continue; } matcher = pattern.matcher(lines[j]); if (matcher.find(offset)) { offset = matcher.end(); line = j; System.out.p...

regex to match postgresql bytea

In PostgreSQL, there is a BLOB datatype called bytea. It's just an array of bytes. bytea literals are output in the following way: '\\037\\213\\010\\010\\005`Us\\000\\0001.fp3\'\\223\\222%' See PostgreSQL docs for full definition of the format. I'm trying to construct a Perl regular expression which will match any such string. It sh...

PHP regex, incorrect escaping of html causing problem

I'm trying to use (.+?) to isolate the words "I. NEED. ISOLATION" in the source below: <strong>Label:</strong></font></td> <td valign="top" width="82%"> <font face="Arial" size="2"> I. NEED. ISOLATION </font> </td> using (.+?), I could do this: $regex = '/stuff before(.+?)stuff after/'; and for this html, that would be...

Ignoring everything but a subfolder in Mercurial

I want to ignore everything BUT a subfolder in Mercurial. The folder I want to keep: a/b/c/d/e/f Everything else under: a/b Should be ignored. I'm using regexp mode in the .hgignore file. This is what I've so far: a/b/(?!c) a/b/c/(?!d) a/b/c/d/(?!e) a/b/c/d/e/(?!f) Even if this works fine, I would like to shrink it to a single...

Find and change a div using a regular expression in Javascript

I am trying to first find a div using a regular expression (since its class name is somewhat dynamic). Once found, I then need to place the div inside of a fieldset, so I end up having a final output of <fieldset class="..."> <div class="the one I found">...</div> </fieldset> How can I do this in javascript? Much thanks, Steve ...

Most concise way to do text replacement on a web page? (using GreaseMonkey)

(Yes, yes, I shouldn't use regexps. Alternate solutions are most welcome!) I'm trying to customize my view of a web page I use a lot, using GreaseMonkey to filter out things I don't want to see. Basically, the pages contain a lot of links that look like this: <a class="foo" href="blah">Text</a> and I'd prefer them to look like this:...

Regex for checking > 1 upper, lower, digit, and special char

Hi all ^.*(?=.{15,})(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*+=]).*$ This is the regex I am currently using which will evaluate on 1 of each: upper,lower,digit, and specials of my choosing. The question I have is how do I make it check for 2 of each of these? Also I ask because it is seemingly difficult to write a test case for ...

Visual Studio: find and replace ALL CAPS with Title Case

Consider the need to replace window titles that are currently in all caps i.e. "ADD PRESCRIPTION", "ADD PATIENT", to the form "Add Prescription" and "Add Patient". I am using the Visual Studio search dialog to find all of the strings that are all caps using the regex "([A-Z]|[ ])*". That works great. Is it possible to find and replac...

Using a regular expression in perl to list variables from another perl script

My thoughts on how to grab all scalers and arrays out of perl file went along the lines of: open (InFile, "SomeScript.pl"); @InArray = <InFile>; @OutArray = {}; close (InFile); $ArrayCount = @InArray; open (OutFile, ">outfile.txt"); for ($x=0; $x<=$ArrayCount; $x++){ $Testline = @InArray[$x]; if($Testline =~ m/((@|\$)[A-Z]+)/i){ $O...

Javascript regular expression

text = '#container a.filter(.top).filter(.bottom).filter(.middle)'; regex = /(.*?)\.filter\((.*?)\)/; matches = text.match(regex); log(matches); // matches[1] is '#container a' //matchss[2] is '.top' I expect to capture matches[1] is '#container a' matches[2] is '.top' matches[3] is '.bottom' matches[4] is '.middle' One solution ...

Need to find if a request queue has gotten to big 1 - 10 of 50

We have a report queue that can get clogged with no good method to monitor. We have a web page in Oracle report builder that can display how reports are in the queue Should always be 1 or 0 So I want to create a bash script to use curl to grep for 1-10 of 10 and if 10 of 10 is not equal ie 10 of 50 to return the first match. ...

Best equivalent for IsInteger in SQL Server

What is the best way to determine whether or not a field's value is an integer in SQL Server (2000/2005/2008)? IsNumeric returns true for a variety of formats that would not likely convert to an integer. Examples include '15,000' and '15.1'. You can use a like statement but that only appears to work well for fields that have a pre-det...

Need Help Parsing File for This Pattern RH 09/27/08 11:49 11:49:00.024

Trying to parse a text file for records starting with an RH space and a date. I need to return the entire line. I expect to find about 6000 in the file. Any help would be greatly appreciated. Example of a full record: RH 09/27/08 11:49 11:49:00.224 COA292 H393 2664FB753 178 -54.82 8.98 C 431 264 13 040 34 24.45-074 58 57.93...

PHP Regular Expression To Match Any URL Except Those From Example.com

Provide an example for the pseudo-regex: Match every url except those from example.com and example2.com according to the PHP regexp syntax. Here is what I have so far, but it doesn't work: $patternToMatch = "@https?://[^(example.com|example2.com)]\"*@i"; ...

Regex in Visual Studio: How to comment out all lines that contain "xyz"?

In Visual Studio 2008, using Regex, how do I comment out all lines containing the text "xyz"? ...