regex

preg_match problem

I'm trying to get some stuff from a string in php. In RegexBuddy and Regular expression tester (firefox addon) it works good, but php gives me the following: Warning: preg_match() [function.preg-match]: Compilation failed: unmatched parentheses at offset 34 in D:\path\example.php on line 62 my pattern is "/.{4}_tmp\\([A-Z...

Regular expressions in ASP.NET

I need a regex pattern to match this format ABC12345678: it should start with ABC and should have preceding 8 numbers. ...

converting into XML

I am trying to convert a conversation I downloaded from Wikipedia into XML. I used the special export to get the page in XML format... that works great until I get to the main conversation. <conversation> {{PersonA|Cheese}} {{PersonB|I like it too...}} {{PersonA|Cheese?}} </conversation> Thats not the real conversation... ...

optional characters in javascript regular expression

I am trying to build a regular expression in javascript that checks for 3 word characters however 2 of them are are optional. So I have: /^\w\w\w/i what I am stumped on is how to make it that the user does not have to enter the last two letters but if they do they have to be letters ...

How do I perform multiple replacements with Perl?

I have Perl code: my $s = "The+quick+brown+fox+jumps+over+the+lazy+dog+that+is+my+dog"; I want to replace every + with space and dog with cat. I have this regular expression: $s =~ s/\+(.*)dog/ ${1}cat/g; But, it only matches the first occurrence of + and last dog. ...

python regex of a date in some text

How can I find as many date patterns as possible from a text file by python? The date pattern is defined as: dd mmm yyyy ^ ^ | | +---+--- spaces where: dd is a two digit number mmm is three-character English month name (e.g. Jan, Mar, Dec) yyyy is four digit year there are two spaces as separators Thanks! ...

Excel Regex, or export to Python? ; "Vlookup" in Python?

heya, We have an Excel file with a worksheet containing people records. 1. Phone Number Sanitation One of the fields is a phone number field, which contains phone numbers in the format e.g.: +XX(Y)ZZZZ-ZZZZ (where X, Y and Z are integers). There are also some records which have less digits, e.g.: +XX(Y)ZZZ-ZZZZ And others with ...

Markdown implementation in PHP parses text within <a> tags — how does one disable this behavior?

I'm using the Markdown library for PHP by Michel Fortin. I started noticing that it formats the text in tags with markdown rules, like so: http://foo.com/My_Url_With_Underscores essentially becomes: <a href="...">http://foo.com/My&lt;em&gt;Url&lt;/em&gt;With_Underscores&lt;/a&gt; How do I disable that behavior or otherwise prevent...

How to use Regex Replace to conditionally remove blocks of text?

I would like to conditionally remove a block of text between specifed start and stop delimiters. The code below does not work, but hopefully it suggests enough of what I am trying to accomplish. If dr("ReferralPoints") > 0 Then Dim objRegex As Regex = New Regex("[HASNOVALUE:REFERRALPOINTS](.*)[/HASNOVALUE:REF...

python regex of a date in some text, enclosed by two keywords

This is Part 2 of this question and thanks very much for David's answer. What if I need to extract dates which are bounded by two keywords? Example: text = "One 09 Jun 2011 Two 10 Dec 2012 Three 15 Jan 2015 End" Case 1 bounding keyboards: "One" and "Three" Result expected: ['09 Jun 2011', '10 Dec 2012'] Case 2 bounding keyboards: "Tw...

Use Java and RegEx to convert casing in a string

Problem: Turn "my testtext TARGETSTRING my testtext" into "my testtext targetstring my testtext" Perl supports the "\L"-operation which can be used in the replacement-string. The Pattern-Class does not support this operation: Perl constructs not supported by this class: [...] The preprocessing operations \l \u, \L, and \U. ...

Advanced Regex: Smart auto detect and replace URLs with anchor tags

I've written a regular expression that automatically detects URLs in free text that users enter. This is not such a simple task as it may seem at first. Jeff Atwood writes about it in his post. His regular expression works, but needs extra code after detection is done. I've managed to write a regular expression that does everything in ...

Regular expression quantifier questions

Hello, Im trying to find a regular expression that matches this kind of URL: http://sub.domain.com/selector/F/13/K/100546/sampletext/654654/K/sampletext_sampletext.html and dont match this: http://sub.domain.com/selector/F/13/K/10546/sampletext/5987/K/sample/K/101/sample_text.html only if the number of /K/ is minimum 1 and maximum ...

Lost in translation - C# regex to JavaScript regex

I'm having some trouble translating my working C# regular expression into JavaScript's regular expression implementation. Here's the regular expression: ([a-z]+)((\d+)([a-z]+))?,? When used on "water2cups,flour4cups,salt2teaspoon" you should get: [ ["water", "2cups", "2", "cups"] ["flout", "4cups", "4", "cups"] ["salt", ...

How can i make my own template/programming engine in php

Ive been working some time on own template engines but i alwais get stuck in strucktured documents like <block : block1> <table> <block : row> <tr> <td> {value} </td> <td> {value2} </td> </tr> ...

Regex Remove Images with style tag from Html

Hi I am new to Regex, however I decided it was the easiest route to what I needed to do. Basically I have a string (in PHP) which contains a whole load of HTML code... I want to remove any tags which have style=display:none... so for example <img src="" style="display:none" /> <img src="" style="width:11px;display: none" > etc... ...

Problem with Regex in .NET (C#)

I'm trying to write a a regex to validate a string to match the following rules. Must start with a-z (case insensitive) Must only contain a-z A-Z 0-9 . - I've put something together based on my limited knowledge and ran it through an online testing tool for a whole bunch of situations and the results were as I had hoped however when ...

How to prevent regex from stopping at the first match of alternatives ?

If I have the string hello world , how can I modify the regex world|wo|w so that it will match all of "world", "wo" and "w" rather than just the single first match of "world" that it comes to ? If this is not possible directly, is there a good workaround ? I'm using C# if it makes a difference: Regex testRegex = new Regex("world|wo|w")...

php/as3 regex to split multiple json in one

For example I have this string of 2 json objects: {"glossary": {"title": "example glossary"}, "aaa": "1212"}{"adada": "faka"} I want to split it in the array for PHP and Actionscript 3 Array ( [0] => '{"glossary": {"title": "example glossary"}', [1] => '{"adada": "faka"}' ) What is the best method to do it. Edit: I don't ne...

C# regular expression for finding forms with input tags in HTML?

Hi all. I have a simple problem: I want to construct a regex that matches a form in HTML, but only if the form has any input tags. Example: The following should be matched (ignoring attributes): .. <form> .. <input/> .. </form> .. But the following should not (ignoring attributes): .. <form> .. </form> .. I have tried everything f...