regex

C# Regex Split To Java Pattern split

I have to port some C# code to Java and I am having some trouble converting a string splitting command. While the actual regex is still correct, when splitting in C# the regex tokens are part of the resulting string[], but in Java the regex tokens are removed. What is the easiest way to keep the split-on tokens? Here is an example of ...

Replace the property value using RegEx

I have config.properties file containing properties in Java Properties format. I need to replace the value of a property with a known name with a new value. The comments and formatting of the file should be preserved. My current approach is to use RegEx to match the property name and then replace its value. However, Java Properties supp...

Need a simple Regular Expressions here

Hi guys, I'm finally parsing through wikipedias wiki text. I have the following type of text here: {{Airport-list|the Solomon Islands}} * '''AGAF''' (AFT) – [[Afutara Airport]] – [[Afutara]] * '''AGAR''' (RNA) – [[Ulawa Airport]] – [[Arona]], [[Ulawa Island]] * '''AGAT''' (ATD) – [[Uru Harbour]] – [[...

How to change this regex to properly extract tag attributes - should be simple

I need to "grab" an attribute of a custom HTML tag. I know this sort of question has been asked many times before, but regex really messes with my head, and I can't seem to get it working. A sample of XML that I need to work with is <!-- <editable name="nameValue"> --> - content goes here - <!-- </editable> --> I want to be able to g...

Need help with Regular Expression to Match Blood Group

Hey guys, I'm trying to come up with a regex that helps me validate a Blood Group field - which should accept only A[+-], B[+-], AB[+-] and O[+-]. Here's the regex I came up with (and tested using Regex Tester): [A|B|AB|O][\+|\-] Now this pattern successfully matches A,B,O[+-] but fails against AB[+-]. Can anyone please suggest...

Regex, match newlines between tags

I have this regex in PHP: preg_match('/\[summary\](.+)\[\/summary\]/i', $data['text'], $match); It works fine when the text between the summary tags is on one line. However, when it contains newlines, it doesn't match. I've tried to find a correct modifier here: http://nl2.php.net/manual/en/reference.pcre.pattern.modifiers.php But th...

What is the XML equivalent of C# Regex.Replace method?

I am validating a Phone Number textbox. I would like to first strip the unneccessary characters from the value entered then validate that the number of characters is not more or less than 11. I know how I would do this in C# code. Unfortunately I now need to do this in an XML document. Validating the length of the corrected data is not a...

How do I replace whitespaces with underscore and vice versa?

I want to replace whitespace with underscore in a string to create nice URLs. So that for example: "This should be connected" becomes "This_should_be_connected" I am using Python with Django. Can this be solved using regular expressions? ...

Getting svn diff to show C++ function during commit

Whenever I do a commit cycle in svn, I examine the diff when writing my comments. I thought it would be really nice to show the actual function that I made the modifications in when showing the diff. I checked out this page, which mentioned that the -p option will show the C function that the change is in. When I tried using the -p ...

Hints for a complex currency regular expression for Javascript?

I need to match an infinite number of figures in a web page. I need to be able to match all of the following formats: 100 $ 99$ $99 $ 8 $.99 $ .8 $ 99.8 .99$ .99 $ 9.2 $ 1.2$ And the equivalent using commas: 444,333 22,333 1,222 11,111,111 333,333,333,333.01132 Or spaces: 444 333 22 333 1 222 11 111 111 333 333 333 333.01132 Th...

Finding characters before last underscore

Hi, Does anyone know how to find all characters before the last underscore in a filename. IABU_Real_Egypt_AUS09_012.indd The result I need is IABU_Real_Egypt_AUS09 Thanks in advance ...

[Haskell] case-insensitive regular expressions

What's the best way to use regular expressions with options (flags) in Haskell I use Text.Regex.PCRE The documentation lists a few interesting options like compCaseless, compUTF8, ... But I don't know how to use them with (=~) ...

Regex can't differentiate between float and int types

I have written regexes for recognizing float and int but they don't seem to work (code below). { string sumstring = "12.098"; Regex flt = new Regex(@" ^[0-9]*(\.[0-9]*)"); Regex ent = new Regex("^[0-9]+"); if (d_type.IsMatch(sumstring)) { Console.WriteLine(sumstring + " " + "dtype"); } Match m = en...

What has higher performance used within large loops: .indexOf(str) or .match(regex)?

I have this array.prototype on my page and it seems to be sucking up a lot of processing time: Array.prototype.findInArray = function(searchStr) { var returnArray = false; for (i=0; i<this.length; i++) { if (typeof(searchStr) == 'function') { if (searchStr.test(this[i])) { if (!returnArray) { r...

Simple RegEx PHP

I have a string and I need to see if it contains the following "_archived". I was using the following: preg_match('(.*)_archived$',$string); but get: Warning: preg_match() [function.preg-match]: Unknown modifier '_' in /home/storrec/classes/class.main.php on line 70 I am new to Regular Expressions so this is probably very easy. O...

PHP RegExp certain chars

What would be a good way to get rid of all chars except, letters, numbers, double quotes and hyphens. This is what I got so far. $test = preg_replace('#[^a-zA-Z0-9"-]#',' ',$string); Any suggestions? Thanks ...

How to recognize special chars in c# (eg = + ! $ %)

This doesn't work: string a = "="; Regex oper = new Regex(@"[=-*/+]"); if (oper.IsMatch(a)) Console.WriteLine("operator"); else Console.WriteLine("yt"); I don't know whether I'm defining regex incorrectly or I'm missing something. Suggestions? ...

Help writing a specific Regular Expression.

Firstly, I'm in C# here so that's the flavor of RegEx I'm dealing with. And here are thing things I need to be able to match: [(1)] or [(34) Some Text - Some Other Text] So basically I need to know if what is between the parentheses is numeric and ignore everything between the close parenthesis and close square bracket. Any RegEx...

Handling Multiple JavaScript Replace Matches

I have the following string: This *is* a *test*! I want to bold the words surrounded by the * characters (so "is" and "test" in the example). I have the following JavaScript code: var data = "This *is* a *test*!"; return data.replace(/\*(.*)\*/g, <b>$1</b>); When the string is returned, I get the following: This <b>is* a *test</b...

.net Split by length

I have a string value that its length is 5000 + characters long , i want to split this into 76 characters long with a new line at the end of each 76 characters. how woudld i do this in c#? ...