regex

What does this if statement containing very similar regular expression matches do?

What does this line of Perl mean? if (/ile.*= (\d*)/ || /ile.*=(\d*)/ ) { I am particularly interested in what the "/ile" means, and why both sides of the || are identical. ...

Regex: match and replace on a date

I'd like to convert the date separators in a date. So, from 11.11.2009 -> 11-11-2009 Could someone help me do that with a regex? ...

Replace first word with last word in C#

Hi I want to replace the following line in C#. Replace first word with last word. I have to remove '[' and ']' from last word as well. string oldString = "200 abc def abc [a18943]" Output should be string newString="a18943 abc def abc"; Thanks ...

Boolean logic in a single regular expression - possible ?

Can we put into a single regular expression , boolean logic : line starts with 'a' or 'b' . Question is triggered by using FileHelpers utility which does have a text box "Record Condition Selector" for "ExcludeIfMatchRegex" . Utility is written in C#. ^a - works , just don't how write down ^a OR ^b ...

Matching a string against a list of words

Say I have the string "i zipped the fezz and it blipped like a baa" and I have an array of words (moo, baa, zip, fjezz, blaa) that I wanted to test to see it they're contained in the string, is there a way of doing so without either using | in the regex or iterating over each word? TIA ...

How to use Regular Expression pattern to replace markup with unquoted attributes values

Consider the following markup <p align=center width='100' height=\"200\" attr=test>aasasd</p> In order to make this markup valid i want to wrap quotes where they are required. From the above exmaple i want to apply quotes so the markup will be: <p align="center" width='100' height="200" attr="test">aasasd</p> Does anyone know any ...

java.util.regex - importance of Pattern.compile()?

What is the importance of Pattern.compile() method? Why do I need to compile the regex string before getting the Matcher object? for example : String regex = "((\\S+)\\s*some\\s*"; Pattern pattern = Pattern.compile(regex); // why i need to compile Matcher matcher = pattern.matcher(text); // ...

Fuzzy Text Search: Regex Wildcard Search Generator?

I'm wondering if there is some kind of way to do fuzzy string matching in PHP. Looking for a word in a long string, finding a potential match even if its mis-spelled; something that would find it if it was off by one character due to an OCR error. I was thinking a regex generator might be able to do it. So given an input of "crazy" it w...

How to retrive number with prep_match_all()

Hi, Inside my webpage "http://www.my_web_page" I have something like that: img border="0" class="borderx" id="pic_15132" I wanna know which parameter did I have to use inside preg_match_all("") to retrive only the number. Here is what I tried but my result is: _15132 $webpage = file_get_contents("http://www.my_web_page"); pre...

PHP RegExp for nested Div tags

I need a regexp I can use with PHP's preg_match_all() to match out content inside div-tags. The divs look like this: <div id="t1">Content</div> I've come up with this regexp so far which matches out all divs with id="t[number]" /<div id="t(\\d)">(.*?)<\\/div>/ The problem is when the content consists of more divs, nested divs like ...

Why does ".*" and ".+" give different results?

Why does ".*" and ".+" give different results? System.out.println("foo".replaceAll(".+", "bar")); // --> "bar" System.out.println("foo".replaceAll(".*", "bar")); //--> "barbar" I would expect "bar" for both, since * and + are both greedy and should match the whole String. (The above example is Java, but other Tools, like http://www.gs...

Regular Expression Conditional Lookahead/Lookback?

Hey guys I wanted to ask if you can do some conditional checks on a single regular expression using lookahead or any other mechanism. For example in my regex I want to the next value to range from 0-5 if the previous was over 3 or range from 0-9 if the previous was under 3. Eg: [0-9] next match should be either [0-5] OR [0-9] dependin...

Regex match A-Z, a-z, 0-9, _ and .

I need a regex which will allow only A-Z, a-z, 0-9, the _ character, and dot (.) in the input. I tried: [A-Za-z0-9_.] But it did not work. How can I fix it? ...

Check if string is of SortableDateTimePattern format

Hi, Is there any way I can easily check if a string conforms to the SortableDateTimePattern ("s"), or do I need to write a regular expression? I've got a form where users can input a copyright date (as a string), and these are the allowed formats: Year: YYYY (eg 1997) Year and month: YYYY-MM (eg 1997-07) Complete date: YYYY-MM-DD (e...

How could I find all whitespaces excluding the ones between quotes?

I need to split string by spaces, but phrase in quotes should be preserved unsplitted. Example: word1 word2 "this is a phrase" word3 word4 "this is a second phrase" word5 this should result in array after preg_split: array( [0] => 'word1', [1] => 'word2', [2] => 'this is a phrase', [3] => 'word3', [4] => 'word4', [5] => 'thi...

Need help with a regular expression in PHP

I have the following line: <?php echo $this->__("mytext");?>somesometext")moretext and I need a regular expression to grab 'mytext'. The best I could come up with is: /\$this->__\([\'"](.*)[\'"]\)/ but in this case it returns: mytext");?>somesometext Can anyone get this to work? ...

Help with regular expression to create definition list

Having trouble wrapping my head around this. I need parse this using a regular expression to create the definition list below Width=3/8 in|Length=1 in|Thread - TPI or Pitch=|Bolt/Screw Length=|Material=|Coating=|Type=Snap-On|Used With=|Quantity=5000 per pack|Wt.=20 lb|Color= The result would be something like this <dt>Width</dt> <dd...

regular expressions in c#

Hi, I need to carry out a task that is to get some html out from a webpage. Within the webpage there are comments and i need to get the html out from within the comments. I hope the example below can help. I need it to be done in c#. <!--get html from here--> <div><p>some text in a tag</p></div> <!--get html from here--> I want it...

Checking a number with regular expressions in Java

I have a number "8756342536". I want to check whether the number starts with "8", contains 10 digits all of it is numeric, using regular expression. What pattern would I need for this scenario in Java? Thanks in advance. ...

Need to prevent PHP regex segfault

Why does the following segfault, and how can I prevent it? <?php $str = ' <fieldset> <label for="go-to">Go to: </label> ' . str_repeat(' ', 10000) . '<input type="submit" value="Go" /> </fieldset> </form>'; preg_match_all("@ </?(?![bisa]\b)(?!em\b)[^>]*> # starting tag, must not be one of several inline tags (?:[^<]|<...