regex

Regular Expression problem: how to determine that there's no B between A and C?

Hi! I need an regular expression that matches A.*C only if there's no "B" in between. Before and after "A.*C without B in between", any string is allowed (including A, B and C). "A", "B" and "C" are placeholders for longer strings. So the regex should match ie. "AfooC", "AfooCbarB", "A C B A", but not "AfooBbarC" or "A B C B". I think ...

What is the PHP equivalent of this JavaScript Regular Expression?

return str.replace(/[\(\)\.\-\s,]/g, "") ...

Remove every <br /> except one per line?

Hello, How can I turn this: ...<br /> <br /> ...<br /> ...<br /> <br /> <br /> ...<br /> Into this using PHP: ...<br /> ...<br /> ...<br /> ... Please notice the deletion of the first and last even if it's mentioned once. In the middle we keep just one ...

regular expression to match -100 to 0

I need a regular expression to match all numbers inclusive between -100 and 0. So valid values are: 0 -100 -40 Invalid are: 1 100 40 Thank you! ...

Get all iframe elements

Hey guys I'm showing a loading indicator while some external iframes are loaded with the following code : <html> <head> <title>Loading iframe</title> </head> <script> function loading_iframe(){ document.getElementById('loading_iframe').style.display = "none"; document.getElementById('loading').style.display = ""; d...

Regular expression: replace email address, with a twist

I have developed a wordpress plugin that looks through a bunch of html and detects any email address, replacing them by a non harvestable html markup (to be rerendered as an email via javascript for better usability). So for instance, the function receives: $content = "Hello [email protected]. How are you today?"; and outputs: $content =...

When to write a parser using grammar vs. using language featured regular expressions.

In my master's I've seen how to write parsers, compilers using ANTLR. But in the real world, often times we have a requirement of parsing and extracting relevant content from a heavy load of in-coming stream data. Each language has it's own regular expression engine which can be conveniently used to parse the data. Alternatively we can w...

split a comma-separated string with both quoted and unquoted strings.

I have the following comma-separated string that I need to split. The problem is that some of the content is within quotes and contains commas that shouldnt be used in the split... String: 111,222,"33,44,55",666,"77,88","99" I want the output: 111 222 33,44,55 666 77,88 99 I have tried this: (?:,?)((?<=")[^"]+(?=")|[^",]+) But it re...

Ant Regular expression, seperate a path into directory name and file name where file name has multiple dots

I am trying to extract the directory and file name from a path. I have got it working with normal file names that only have a single dot as part of the extension name, but it fails to work if there are multiple dot's in the file name. Normal case results in: Web Content/javascript/more/andmore/evenmore AND uidoublerebel I am wanti...

Parsing text for email id's

I am trying to parse text for email id's using php / regex. Are there any classes or built in methods to do this? The text contains multiple email id's at random places. The source of the text is .doc files, which I then copy paste into forms, to be processed on submit. preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $email) //from ...

Perl Regular Expressions: Question mark isn't greedily matching.

$var = 'about/'; $var =~ s/^(.*)\/?$/index.php?action=$1/; I want it to match and substitute the trailing slash. But it isn't, I'm getting this result: index.php?action=about/ What am I doing wrong? I've tried wrapping it in parenthesis (\/)? and including the question mark in the parenthesis (\/?). Not including the preceding fo...

Comparing text blocks for similar content

I have two text blocks, containing company names. Both contain names of hundreds of companies, the newer list has more companies. How do I remove the duplicate company names from the two lists , so that I am left with the new names only? Sample text block one: Company Name One, Address line 1, line 2, phone, email .. Random text .. Co...

VB.Net Regular expression

I want to have a string in the following format "FAG001 FAG002 FAG003" and want to split it into "FAG001" "FAG002" "FAG003" using a regular expression. Unfortunately my knowledge of regular expression synatax is limited to say teh least. I have tried things like Dim result = Regex.Split(npcCodes, "([A-Z]3[0-9]3)").ToList withou...

Need a regular expression that matches “word1, word2, word3”

Hi guys, I'm trying to construct a regular expression that would match a pattern as such: word1, word2, word3 So basically I want ", " to appear twice and to have words between them. So far I came up with: $general_content_check = preg_match("/^.*, .*$/", $general_content); But this matches only ", " several times in a string. Ca...

Java Regex pattern to get anchor text

I have a page source and i want to get the anchor text of all its anchor tags Could someone please help me out with the pattern for it. Thanks in Advance ...

Unterminated Parenthetical error with a Regular Expression in Javascript

I am trying to use the following regular expression to validate a date in javascript (sorry it's a bit of a brute): "/^(((0[1-9]|[12][0-9]|3[01])\/(0[13578]|1[02])\/((19|[2-9][0-9])[0-9]{2}))|((0[1-9]|[12][0-9]|30)\/(0[13456789]|1[012])\/((19|[2-9][0-9])[0-9]{2}))|((0[1-9]|1[0-9]|2[0-8])\/02\/((19|[2-9][0-9])[0-9]{2}))|(29\/02\/((1[6-9]...

[Javascript]Regex Expression

Hi, I have this string: Tue,Sep,21,15:48:1,CEST,2010 I would replace the "," with a space. I have tried: string=string.replace("/,/g"," "); and the result is: Tue,Sep,21,15:48:1,CEST,2010 I have tried: string=string.replace(","," "); and the result is: Tue Sep,21,15:48:1,CEST,2010 How can I replace all the "," with " "? ...

What is the power of regular expressions?

As the name suggests we may think that regular expressions can match regular languages only. But regular expressions we use in practice contain stuff that I am not sure it's possible to implement with their theoretical counterparts. How for example would you simulate a back-reference? So the question arises: what is the theoretical power...

Modifying back reference on regular expression (PHP)

Getting frustrated... So, I want to modify the back reference of a preg_replace. Figured I can't actually modify (?) so am wondering if it's possible to change the regex to achieve same result. Example. Match [xx_xx] and output "xx_xx" and "xx xx". The "xx_xx" is straightforward (as follows) but the "xx xx" ? $y = "this [fishing_rod]...

Regex for detecting the same character more than five times?

Hi, I'm trying to figure out how to write a regex that can detect if in my string, any character is repeated more than five times consecutively? For example it wouldn't detect "hello", but it would detect "helloooooooooo". Any ideas? Thanks Edit: Sorry, to clarify, I need it to detect the same character repeated more than five times, n...