regex

JFormattedTextField using a regular expression formatter?

After much frustration with getting a JFormattedTextField to work with my custom formats, I was wondering if there was a Formatter or FormatterFactory that uses regular expressions? My idea is that if there is one, then I could wrap it in a static class and invoke it like so: mFormattedTextField.setFormatterFactory( SomeStaticClass...

Extracting number preceding a particular text using a regex

I'm looking for a regex to extract two numbers from the same text (they can be run independently, no need to extract them both in one go. I'm using yahoo pipes. Source Text: S$ 5,200 / month Negotiable, 1,475 sqft / 137 sqm (built-in) - Apartment, 10 Anson Road (D02) Need to extract as a number: 1,475 and also (but can be extracted on...

C#: How should I convert the following?

Using C#, how would you go about converting a String which also contains newline characters and tabs (4 spaces) from the following format A { B { C = D E = F } G = H } into the following A.B.C = D A.B.E = F A.G = H Note that A to H are just place holders for String values which will not contain '{', '}', and '=...

RewriteCond match for certain parameter values, part 2

Before I begin, let me just say that I know my question is almost identical to this one. The difference is that, while I am trying to use a RewriteCond to identify a specific parameter in the query and redirect appropriately, I do not want the query string appended to the resulting URL. Here's what I'm trying to do in my .htaccess file...

how to remove the backslash in string using regex in java

how to remove the backslash in string using regex in java example : String is "hai how are\ you?" i want only hai how are you?. please help me... ...

Regex Question Again!

I really don't know what my problem is lately, but Regex seems to be giving me the most trouble. Very simple thing I need to do, but can't seem to get it: I have a uri that returns either /xmlfeed or /xmlfeed/what/is/this I want to match /xmlfeed on any occasion. I've tried many variations of the following: preg_match('/(\/.*?)\/...

Regex for adding a versionnumber to .js and .css references in a HTML document

Hi folks, I have a HTML document where I want to automatically have a version number added to all script and style sheet references. the following should be replaced <link ... href="file.css" media="all" /> <script ... src="file.js"></script> <script ... src="http://myhost.com/file.js"&gt;&lt;/script&gt; with that <link ... hre...

RegEx for cleanup a string

This RegEx is for cleanup user input from a search form $query = preg_replace("/[^A-Za-z0-9 _.,*&-]/", ' ', $query); I need to add the slash as a valid character too, but if I add it, I get an error. I assume I have to escape it but can't find how to do that $query = preg_replace("/[^A-Za-z0-9 _.,*&-/]/", ' ', $query); // doesn't wor...

Multi level .Net Regex

If I have input string in C#, how can I do series of Regex / linq operations on it to do Regex match on one piece of string and then another Regex on all pieces of string which are not matched by 1st Regex. In other words, for input string: <!-- Lorem ipsum dolor sit amet, consectetur adipiscing elit --> <!-- The quick brown fox jump...

Regular Expression for field must contain at least 2 non-space alphanumeric characters.

Hi all, Rule: field must contain at least 2 non-space alphanumeric characters. please any one can guide us how to write the regular expression thanks in advance.... ...

PHP Regex - text into link

What I'm trying to do is, replacing symbols that would be changed start the string then the last symbol that would close the string - changing both of them into a link then it will be stored into the database, it's something like Wikipedia. I want to have something like this when someone types in the textarea: "This woman was killed by...

Regex: Match thingies within paragraph

I want to match the values for A and C, but only if they are within the same paragraph. A:one C:foo A:two B:rofl, some rubbish ::: A:three B:lol C:bar Right now I'm using /A:([a-z]*).*?C:([a-z]*)/s But that gives me "two" and "bar", which don't belong together. How do I exlude the empty line in my /.*?/ ? ...

Shortlinks RewriteRule Regex

Hi, I'm using Apache/PHP to support shorlinks to documents and I'm having trouble with the Regex to redirect correctly. My links take the form of 8 letters/numbers, something like '1abc45fd', I would like to have them redirect to /shortlink.php?link=1abc45fd but it's just not working correctly. I'm using the following expression: "Rewr...

What is the longest regular expression you have seen

I just found an extremely long regular expression (6000+ characters) for a WordPress email validation. That got me thinking, what is the longest one you have ever actually seen that is being used in a production environment. ...

Get more backreferences from regexp than parenthesis

Ok this is really difficult to explain in English, so I'll just give an example. I am going to have strings in the following format: key-value;key1-value;key2-... and I need to extract the data to be an array array('key'=>'value','key1'=>'value1', ... ) I was planning to use regexp to achieve (most of) this functionality, and wrot...

Regex Alternation returning string

I've been trying desperately to return a text string in addition to captures groups from a regular expression using alternation. Here's what I have; (?<make>(?:\w*|\w*\s\w*));(?<score1>\d{1,2});(?<score2>\d{1,2});(?<model>\w{1,})(?(model)No|Yes) My Data; Austin;1;2;Taxi Audi;2;4;Quattro BMW;4;5;M3 Ferrari;10;10;F40 Fiat;4;2;Panda ...

Regex for quoting unquoted XML attributes

Edit: The 100% correct theory is that you don't want to do this at all. However I have accepted the answer that helped the most. So I'm being given ugly XML from a client that promises to fix it. In the meantime I need to clean it up myself. I'm looking for a regex to use in Java to add quotes around unquoted attributes. The general cas...

Modify SQL SELECT statement with PHP

How best to alter a SQL SELECT statment's field list to a COUNT(*) using PHP? e.g SELECT blah, blah, blah FROM tbl_blah WHERE blah; to SELECT COUNT(*) FROM tbl_blah WHERE blah I have considered mysql_num_rows... but I am pretty sure it would be more efficient to edit the statement. I am guessing it could be solved with a regex expr...

Mercurial .hgignore Negative Lookahead

Using Mercurial, I need to ignore all files except for those in a certain directory called "keepers". On the face of things, this seemed easy using Regex and Negative Lookahead; however, although I am able to verify my regex in Regex Buddy and other tools, in TortoiseHg, it doesn't work as expected. Files: junk\junk.txt junk\text kee...

How to convert a csv list (horizontal) from vertical name value pair set

I have a list like this: GTPYANJ 695848 GTPYANJ 27811 FPORTAL3 432532 I want to turn it into this using regular expressions: GTPYANJ,695848,27811 FPORTAL3,432532 Suggestions? ...