regex

What are the best places to learn regular expression (PHP)?

What are the best places to learn regular expression (PHP)? ...

Regex for decimal numbers

Could anybody provide a regular expression for a number that has to be between 1 and 17 in length, and could optionally contain a mantissa of up to 4 places? The length of 17 includes both the characteristic and the mantissa. Edit: The length of 17 excludes the decimal point. Valid examples: 12345678901234567 1234567890123.4567 ...

Why does sed require 3 backslashes for a regular backslash?

I'm curious, why does sed need 3 \ just to recognize one? I'd understand it needing 2, but 3 I don't. EDIT: here's an example on my Windows computer, using Cygwin: echo "sample_input\whatever" | sed "s/\\\/\//" If I don't add 3 backslashes, I get a sed: -e expression #1, char 7: unterminated s' command. ...

How can I build a regular expression which has options part

Hi, How can I build a regular expression in python which can match all the following? where it is a "string (a-zA-Z)" follow by a space follow by 1 or multiple 4 integers which separates by a comma: Example: someotherstring 42 1 48 17, somestring 363 1 46 17,363 1 34 17,401 3 8 14, otherstring 42 1 48 17,363 1 34 17, I have tried th...

Oracle regex: \Q\E doesn't work

Hi. I found that \Q\E doesn't work in oracle. What is the equivalent expression of \Q\E for oracle regex ? TIA ...

Regular Expression for password validation

Hi, can any one help me in creating a regular expression for password validation. The Condition is "Password must contain 8 characters and at least one number, one letter and one unique character such as !#$%&? " ...

StackOverflowError occured as using java.util.regex.Matcher

Hi guys I try to catch text by Regular Expression. I list codes as follows. Pattern p=Pattern.compile("<@a>(?:.|\\s)+?</@a>"); Matcher m = p.matcher(fileContents.toString()); while(m.find()) { //Error will be thrown at this point System.out.println(m.group()); } If the length of text I want to catch is too long, system will...

How do I ensure I always get a list of matches from Python's Regular Expressions?

I'm trying to pull some information (no recursion necessary) from a jsp page (malformed xml) similar to this: <td> <html:button ...></html:button> <html:submit ...></html:submit></td> And a regex: <html:(button|submit|cancel)[\s\S]*?</html:(button|submit|cancel)> re.findall() is giving me a list of tuples, like so: [('button','but...

Regular expression help.

I don't know regular expression at all. Can anybody help me with one very simple regular expression which is, extracting 'word:word' from a sentence. e.g "Java Tutorial Format:Pdf With Location:Tokyo Javascript"? Little modification: the first 'word' is from a list but second is anything. "word1 in [ABC, FGR, HTY]" guys situation de...

Java: use scanner delimiter as token

Hi, I'm trying to find a good way to get a Scanner to use a given delimiter as a token. For example, I'd like to split up a piece of text into digit and non-digit chunks, so ideally I'd just set the delimiter to \D and set some flag like useDelimiterAsToken, but after briefly looking through the API I'm not coming up with anything. Right...

Sanitization of User-Supplied Regular Expressions in PHP

I want to create a website where users can test regular expressions (there are many out there already...such as this one: http://www.pagecolumn.com/tool/pregtest.htm). Basically, the user provides a regular expression and some sample text, and the results of the regex evaluation will be spit back. I want to evaluate the regex on the ser...

Matching paragraphs with regex

Can somebody explain me why the following text: <p>some text some text...</p> <p>another text another <b>text</b>again</p> can't be parsed with the following regular expression: <p>.*?</p> (to retrieve every paragraph). The regular expression that should match the text between the first opening <p> tag and the last closing </p> tag...

php, second last comma in a string to break string, or regex

I'm trying to find a way to break a string at the second last comma, for example: piece 1, piece 2, piece 3, piece 4, piece 5, piece 6, piece 7 should be 2 parts: piece 1, piece 2, piece 3, piece 4, piece 5 and piece 6, piece 7 and piece 1, piece 2, piece 3, piece 4, piece 5 should be: piece 1, piece 2, piece 3 and piece 4, piec...

JS / Ruby : partial replacement using regexp.

Hi, I'm trying to replace different parts of a html code using a single regexp. For exemple i have this text : option_!!NID!! [somme_text][5] some_text_option 5_option_some_text using this regexp: content.replace(/(!!NID!!)|\[(\d)\]|(\d)_option/g, 1)) I expect to get : option_1 [somme_text][1] some_text_option 1_option_some_text ...

Can regular expressions work with different languages?

English, of course, is a no-brainer for regex because that's what it was originally developed in/for: Can regular expressions understand this character set? French gets into some accented characters which I'm unsure how to match against - i.e. are è and e both considered word characters by regex? Les expressions régulières peuv...

Replacing only full words in a string with Regex

I need to replace only the first occurrence of a word in a sentence with regex. Part of the problem is solved, but I need to replace only full words, and exclude partial matches. For example, in the sentence "The quick brown foxy fox jumps over the lazy dog", I would like to replace "fox" by "cat". The result that I could achieve was...

Safely split/paginate an HTML String with ASP.NET

I have rendered one of my controls into a string. I want to safely split the html string. I don't want any hanging html tags. I am working on a pagination control adapter. How can I split my string, around less than a set number of chars) safely taking HTML into account? ...

Regex: keep everything in <profession></profession> tags

I have a large XML, looking like this: <gender>M</gender> <last-name>*</last-name> <profession>2165dda2-dc59-41af-acb5-06d8914c4841</profession> <first-name>*</first-name> <mail-confirmation>1</mail-confirmation> <fax-confirmation>1</fax-confirmation> I only want to keep the tags. I found a way to search IN the tag, like this: <prof...

Purpose of JSLint "disallow insecure in regex" option

I have a line of code that gets the following error when run through JSLint: Lint at line 604 character 48: Insecure '^'. numExp = parseInt(val[1].replace(/[^\-+\d]/g, ""), 10); This error seems to refer to the following description from JSLint's option page: "true if . and [^...] should not be allowed in RegExp literals. These form...

C# Regex parsing HTML

Hi all; <tr><TD><FONT size="2">My Value 1</FONT></TD></tr> I need "My Value 1" Please Help Me. C# language ...