regex

Trouble With/Confused By Java.util.Scanner's next(Pattern) Method

I've constructed a regular expression which I compile to a Pattern to find Fortran Real*8 numbers. The tricky bit is that the file I'm reading from is a single line with a few million columns.. When I do this: Scanner recordScanner = new Scanner(recordString); String foundReal = recordScanner.findInLine(real8Regex); I get what I'm lo...

Regex PHP question

Guys, Not gonna lie, I'm terrible at regex. How would I be able to do this guys: $string = '>Data 1-23</a>'; $string = '>Datkl3</a>'; $string = '>RA Ndom</a>'; And pull out the "Data 1-23" from inside the above string using regex? And if I have multiple ones of this, how would I be able to put all of the matched strings into an arra...

given 2 urls, how to tell that they are actually referring to the same website or webpage?

i am using Php. given 2 urls like this, http://soccernet.com and http://soccernet.espn.go.com/index?cc=4716 how to tell that they are actually the same? also consider situation where the difference is the httpS, like https://gmail.com and http://gmail.com please advise. I am finding it a struggle at using regex because sometimes it ...

Another PHP regex question

Guys, this probably will be fairly simple, but how am I able to find all the matches using regex of this occurrence in a load of text. [[data in here]] EG: Blah blah blah [[find]] and maybe [[this]] So I am able to find the occurrences and then replace them as urls. Does that make sense? I tried using preg_match_all("/[[([^<]*)]...

PHP Regex match all HTML tags

I am reading contains of an HTML page for some details, I'm searching for every occurrence of a string, that string comes withing a tag, I want to read just that string only. Example: <a href="http://www.example.com/search?la=en&amp;q=javascript"&gt;javascript&lt;/a&gt; <a href="http://www.example.com/search?la=en&amp;q=PHP"&gt;PHP&l...

Matching AS3 arguments with Ruby RegEx

Hi I'm trying to extract the parameters from a class definition. class locale.company.app.LoginData(username:String, password:String) I have extracted the package name and class name, but the parameters are causing me some trouble. I used Rubular to construct the following regex: http://www.rubular.com/regexes/9597 According to Ru...

Regular Expression: /.+?/

How would the '.+?' regular expression work? Is the .+ part matching anything written, and the ? part saying it can either be there or not? So, for example, this regular expression would match: 'cat' '' (ie, nothing written, just the empty string) ...

Ruby, gsub and regex

Quick background: I have a string which contains references to other pages. The pages are linked to using the format: "#12". A hash followed by the ID of the page. Say I have the following string: str = 'This string links to the pages #12 and #125' I already know the IDs of the pages that need linking: page_ids = str.scan(/#(\d*)/)....

CodeIgniter Routing

I am developing an ecommerce website with CI that has product categories and products. I want to route the URL so that it will go to the products controller, then run the getCategoryByName function for the first segment, then run the getProductByName for the second segment. Here is what I have: URL: products/docupen/rc805 routes.php...

What's the difference between these perl compatible regular expressions?

An answer from another question piqued my curiosity. Consider: $string = "asfasdfasdfasdfasdf[[sometextomatch]]asfkjasdfjaskldfj"; $regex = "/\[\[(.+?)\]\]/"; preg_match($regex, $string, $matches); $regex = "/\[\[(.*)\]\]/"; preg_match($regex, $string, $matches); I asked what the difference between the two regexes is. The aswer I ...

How to replace all occurences of a variable in a string using javascript?

I'm trying to replace all the occurrences of a variable in a string using javascript. This is not working.: var id = "__1"; var re = new RegExp('/' + id + '/g'); var newHtml = oldHtml.replace( re, "__2"); This is only replacing the first occurrence of id: var id = "__1"; var newHtml = oldHtml.replace( id,"__2"); What am I doing w...

python regex help: unknown information to skip

I'm having trouble with the needed regular expression... I'm sure I need to probably be using some combination of 'lookaround' or conditional expressions, but I'm at a loss. I have a data string like: pattern1 pattern2 pattern3 unwanted-groups pattern4 random number of tokens pattern5 optional1 optional2 more unknown unwanted junk sepa...

Regex return value between two values?

Is it possible to return a string between 2 strings, using regex? For example, if I have this string: string = "this is a :::test??? string"; Can I write a function to return the word "test" using a regex? Edit: Sorry, I'm using C# ...

Regex to replace gibberish

I have to clean some input from OCR which recognizes handwriting as gibberish. Any suggestions for a regex to clean out the random characters? Example: Federal prosecutors on Monday charged a Miami man with the largest case of credit and debit card data theft ever in the United States, accusing the one-time government informant of ...

Help with regex validation on string of text in c#

Hi, im trying to validate a string of text that must be in the following format, The number "1" followed by a semicolon followed by between 1 and three numbers only - it would look something like this. 1:1 (correct) 1:34 (correct) 1:847 (correct) 1:2322 (incorrect) There can be no letters or anything else except numbers. Does anyo...

How to recognize two different word in a regex without grouping

Hi, I've got a Regex question, I have to recognize tokens in a text that are like: Foo- followed by either bar or baz followed by - then some numbers, like: Foo-bar-010 Foo-baz-101 I then want to divide my matches like : Foo-bar -010 and Foo-baz -101 My regex is this one: (Foo-(bar|baz))-[0-9]+ Which is kinda cool, but I don'...

Can preg_match() (or other php regex function) match a variable number of parenthesized subpatterns?

Suppose I have '/srv/www/site.com/htdocs/system/application/views/' and want to test it against a regexp that matches each directory name in the path? Something like this pattern: '(/[^/])' That yields an array with 'srv','www','site.com'... etc. PS: the regexp syntax I wrote is just to illustrate, it's not tested and surely wrong, but...

Regex to parse international floating-point numbers

I need a regex to get numeric values that can be 111.111,11 111,111.11 111,111 And separate the integer and decimal portions so I can store in a DB with the correct syntax I tried ([0-9]{1,3}[,.]?)+([,.][0-9]{2})? With no success since it doesn't detect the second part :( The result should look like: 111.111,11 -> $1 = 111111; ...

php: preg replace a single question mark?

How do I replace a single question mark with preg replace. ...

CAtlRegExp for a regular expression that matches 4 characters max

Short version: How can I get a regex that matches [email protected] but not [email protected] using CAtlRegExp ? Long version: I'm using CAtlRegExp http://msdn.microsoft.com/en-us/library/k3zs4axe(VS.80).aspx to try to match email addresses. I want to use the regex ^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$ extracted from here. But the syntax t...