regex

PHP regex - find and replace

Hi, I am trying to do this regex match and replace but not able to do it. Example <SPAN class="one">first content here</SPAN> <SPAN class="two">second content here </SPAN> <SPAN class="three">one; two; three; and more.</span> <SPAN class="four">more content here.</span> I want to find each set of the span tags and replace with somet...

Which POSIX flavor of regex does Perl use?

Specifically, I'm using the Linux command: $ find . -regextype posix-extended -regex '<some regex>' ... I just want to make sure the POSIX type I'm using is the type Perl uses, since that is by far the one I am most familiar with. ...

Regex to exclude 1 word out of a regex code.

I need a regex expert to help out on this one. Examples I've found on here and the net I cant seem to get right. I'm using PHP and I have the following regex expression /([^a-zA-Z0-9])GC([A-Z0-9]+)/ This matches items like GCABCD GC123A, etc. What i need to do is EXCLUDE GCSTATS from this. So basically I want it to work just as it...

How do I get the length of a regex match in vim?

If I want to get the length of each match within the parentheses in the following regex, how do I do it?: ^\(\-\+\s\)\+ I'm trying to modify the width of columns in a buffer with data that is laid out as a table. Since the first two rows of the table will look like this DESIGN_ID DESIGN_YEAR SOURCE_REFERENCE ---------- ----------- ...

Regex to test if an input string contains a certain number of characters

So, I basically would like to test to see if a string contains a range of alphanumeric characters. It's to be used as a client-side validation and I don't want to prevent users from entering whatever they want. Best to give examples of what should/should not pass validation: So to be specific, the expression I'm looking for is to test t...

Matching math expression with regular expression?

For example, these are valid math expressions: a * b + c -a * (b / 1.50) (apple + (-0.5)) * (boy - 1) And these are invalid math expressions: --a *+ b @ 1.5.0 // two consecutive signs, two consecutive operators, invalid operator, invalid number -a * b + 1) // unmatched parentheses a) * (b + c) / (d // unmatched parentheses I hav...

.NET Regular Expression for Regular Expression Parsing

I want to return matches from a regular expression string. The regex string is: (?<TICKER>[A-Z]+)(?<SPACE>\\s)(?<MONTH_ALPHA_ABBREV>Jan|Feb|Mar|Apr|May|Jun|Jul|Sep|Oct|Nov|Dec)(?<SPACE>\\s)(?<DAY>\\d+)(?<SPACE>\\s)(?<YEAR_LONG>[2][0][0-9][0-9])(?<SPACE>\\s)(?<STRIKE_DOLLAR>\\d+(?=[.]))[.](?<STRIKE_DECIMAL>(?<=[.])\\d+)(?<SPACE>\\s)(?<PU...

How do I write a regex that ignores strings starting with a particular prefix, and captures everything else into a single group?

Background: I'm trying to come up with a regex for a rewrite rule that will take anything that does not start with a particular prefix, and add that prefix to it. But urls that already have the prefix should be rejected by the regular expression (because they already have the url). Example: If the prefix is s1 a string like home will...

jQuery regex over multiple lines

I have the following string: <img alt="over 40 world famous brandedWATCHES BRANDs to choose from " src="http://www.fastblings.com/images/logo.jpg"&gt;&lt;/strong&gt;&lt;/a&gt;&lt;br&gt; I want to define a regex pattern like <img alt="(.+?)" src="http://(.+?).(jpg|gif)"&gt;, but as you can see the target string has a linebreak in the a...

Regex to split on successions of newline characters

I'm trying to split a string on newline characters (catering for Windows, OS X, and Unix text file newline characters). If there are any succession of these, I want to split on that too and not include any in the result. So, for when splitting the following: "Foo\r\n\r\nDouble Windows\r\rDouble OS X\n\nDouble Unix\r\nWindows\rOS X\nUni...

how can i say `from beginning to $string` and `from $string to the end` in regexish for php

Hi, I want to remove a part from a text till the given string, and remove another part starting from another string in php. /.+string/i and /anotherstring.+/i didn't work. ...

Regex: Matching against groups in different order without repeating the group

Let's say I have two strings like this: XABY XBAY A simple regex that matches both would go like this: X(AB|BA)Y However, I have a case where A and B are complicated strings, and I'm looking for a way to avoid having to specify each of them twice (on each side of the |). Is there a way to do this (that presumably is simpler than h...

Regex to match words and those with an apostrophe

Update: As per comments regarding the ambiguity of my question, I've increased the detail in the question. (Terminology: by words I am refering to any succession of alphanumerical characters.) I'm looking for a regex to match the following, verbatim: Words. Words with one apostrophe at the beginning. Words with any number of non-con...

How do I locate a particular word in a text file using .NET

I am sending mails (in asp.net ,c#), having a template in text file (.txt) like below User Name :<User Name> Address : <Address>. I used to replace the words within the angle brackets in the text file using the below code StreamReader sr; sr = File.OpenText(HttpContext.Current.Server.MapPath(txt)); copy = sr.ReadToEnd(); sr.Close(...

Regex to parse youtube yid

Example URLs http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo http://www.youtube.com/watch?v=cKZDdG9FTKY&amp;feature=channel http://www.youtube.com/watch?v=yZ-K7nCVnBI&amp;playnext_from=TL&amp;videos=osPknwzXEas&amp;feature=sub http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I Any regex that will pull the correct YID from a...

Regex for capturing a character between a group but ignoring the ones in a nested group.

This is for make something similar to "templates" in MediaWiki with PHP in order to make the parameters between nested templates work. Is possible with a regex to capture all occurrences of a character between braces but ignoring occurrences of it if it occurs in a nested group of braces? | {{ | {{ | }} | | }} | Highlighted: | {{ *|...

iPhone dev: Replace uppercase characters in NSString with space and downcase

I have: NSString *promise = @"thereAreOtherWorldsThanThese"; which I'm trying to transform into the string: @"There are other worlds than these" I'm guessing this is a regex job, but I'm very new to Objective C, and have so far had no luck. I would greatly appreciate any help! ...

How can I extract a value from comma separated values in Perl?

I have a log file containing statistics from different servers. I am separating the statistics from this log file using regex only. I am trying to capture the CPU usage from the running process. For SunOS, I have below output: process,10050,user1,218,59,0,1271M,1260M,sleep,58.9H,0.02%,java Here the CPU % is at 11th field if we separa...

format string (postcode) in ruby

I need to re-format a list of UK postcodes and have started with the following to strip whitespace and capitalize: postcode.upcase.gsub(/\s/,'') I now need to change the postcode so the new postcode will be in a format that will match the following regexp: ^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-...

A solid nickname regexp

I want a regular expression to validate a nickname: 6 to 36 characters, it should contain at least one letter. Other allowed characters: 0-9 and underscores. This is what I have now: if(!preg_match('/^.*(?=\d{0,})(?=[a-zA-Z]{1,})(?=[a-zA-Z0-9_]{6,36}).*$/i', $value)){ echo 'bad'; } else{ echo 'good'; } This seems to work, but when...