regex

What do these Perl regexes mean?

What does the following syntax mean in Perl? $line =~ /([^:]+):/; and $line =~ s/([^:]+):/$replace/; ...

Beginner JavaScript RegEx Question: How to remove all characters from a string ?

How can I remove all characters from a string that are not letters using a JavaScript RegEx? ...

Repeated Regex groups

I have a pattern like this that matches multiple sets of values: (((\w+) (\d+))+) I think this would match: one 1 two 2 three 3 four 4 five 5 But because I don't know how many repeats there are I don't know what to put in the output. For instance I need to get the results into something like this: <span class="one">1</span> <span...

Regular expression for validating a url

Hi, I'm a beginner in regexes. My requirement is to validate simple urls to urls with query strings, square brackets etc.. say for eg, www.test.com?waa=[sample data] the regex that I wrote only work for simple urls. It fails for the one with square brackets. Any idea? ...

How do you create a Regular Expression for a domain list?

This is for a textbox validation. I need to match on a list of domains MATCHES google.com, msn.com, texas.edu.gov.us msn.com NON-MATCHES google.com, msn.com, @msn.com, @google.com [email protected] without the trailing comma (that's where I'm getting stuck) This is what I have so far but the comma delimited part...

Matching multiple sporadic groups in a regex

I'm dealing with some legacy code that stores its data in a proprietary string format and I'm trying to create a regex to make parsing this format much easier. What I'm having trouble with is the format contains groups that can be repeated many times sporadically. For example typically the data will look liks this (A)(B)(B)(B), but some...

split a string by a delimiter in a context sensitive way

For example, I want to split str = '"a,b,c",d,e,f' into ["a,b,c",'d','e','f'] (i.e. don't split the quoted part) In this case, this can be done with re.findall('".*?"|[^,]+',str) However, if str = '"a,,b,c",d,,f' I want ["a,,b,c",'d','','f'] i.e. I want a behavior that is like python's split function. Is there any way ...

How do I make a regex NOT match when I first find something unwanted

I want to use a regex to find a particular string in my sample, but I want the regex to fail if I first find another string. Let me give an example: Match find_me only if we do not first encounter stop_here. (I don't care if stop_here occurs later in the sample.) So, this should match: blah blah find_me blah stop_here But this shou...

Help with drivers license number validation regex

I'm trying to validate a drivers license for a form that i am making. I was trying to use a single regex. Max length 9 characters Alphanumeric characters only Must have at least 4 numeric characters Must have no more than 2 alphabetic characters The third and fourth character must be numeric I'm new at regex I'm googling trying to w...

Splitting text

I want to know is there any way to split text like this: 123456789 into 123-456-789 as to add "-" after every 3 characters? Just wanted to know, as I know the reverse, but how to do this is over my head. ;) and also if the text is ABCDEFGHI OR A1B2C3D4E or any other format without any space between the characters ! languge : PHP...

how to find a string containing a square bracket?

i'm using a regular expression to search for a bunch of keywords in a text. All keywords are found but one: [DAM]Berlin. I know it contains a square bracket so i escaped it, but still, no luck. What am i doing wrong? here is my php code. The text to search for keywords: $textToSearch= '<p><br> Time ¦ emit LAb[au] <br> <br> [DAM]Berli...

Percent symbol in codeigniter URI

I need to pass an encoded string to a codeigniter controller. Ex: DOSOMETHING/Coldplay/Fix+You/273/X+%26+Y/ My problem is with the percent symbol, has disallowed characters. I tried to change the config file with: $config['permitted_uri_chars'] = 'a-z 0-9~%.:_-+\%'; The + is ok but the % is not valid. Can you help me to change this r...

how to eliminate dots from filenames, except for the file extension

I have a bunch of files that look like this: A.File.With.Dots.Instead.Of.Spaces.Extension Which I want to transform via a regex into: A File With Dots Instead Of Spaces.Extension It has to be in one regex (because I want to use it with Total Commander's batch rename tool). Help me, regex gurus, you're my only hope. Edit Several ...

Regexp require # of non-whitespace characters

I have a textarea. I am trying to check that it contains atleast 3 non-whitespace characters in javascript, and if it does, I need to recheck the posted message in php. I think once I get it working in php, I can use the same regexp for javascript. However, the whitespaces are messing it up. I don't understand why the following does no...

Regular Expression matching either a single special character OR a particular sequence

Not sure if I'm doing this right: /(https?:\/\/\S+)(\s|(& nbsp;))?/g; This should match a URL beginning with http(s):// and ending with a space character or a & nbsp; So the problem is this part: (\s|(& nbsp;))? That should mean: match either a white space or a & nbsp; but it doesn't work. It never matches for a & nbsp; and just c...

Get text between symbols, regex?

Hello guys, I have a problem, i can't figure out a way to get out text between symbols. site.com/hello-world/my-page-title/ i want to get my-page-title only? How? Thanks for your help, ...

Is there a utility that will convert POSIX to PCRE for PHP?

Is there a utility that will convert POSIX to PCRE for PHP? I'm somewhat confused by the PHP manual on PCRE, and while I'll try to find more info on PCRE, I was wondering if anyone had designed such a utility. Or, if anyone would explain how to convert the following, that would also be fine: ereg("^#[01-9A-F]{6}$", $sColor) But pleas...

Matching Lua's "Long bracket" string syntax

I'm writing a jFlex lexer for Lua, and I'm having problems designing a regular expression to match one particular part of the language specification: Literal strings can also be defined using a long format enclosed by long brackets. We define an opening long bracket of level n as an opening square bracket followed by n equal signs fo...

second or third time a symbol appears

In PHP $regex = '/ ([$]) *(\d+(:?.\d+)?)/'; preg_match($regex, $str, $matches); print_r($matches[2]); This regex gives me the first occurence of a number that follows the first $ sign in a web page. Now I want a regex that would give me the number after the second $ sign and maybe the third too. ...

It is possible to match a character repetition with regex? How?

Question: Is is possible, with regex, to match a word that contains the same character in different positions? Condition: All words have the same length, you know the character positions (example the 1st, the 2nd and the 4th) of the repeated char, but you don't know what is it. Examples: using lowercase 6char words I'd like to match w...