regex

Regular expression for staff member

Hi, I am trying to get a regular expression that will match on any of the following strings: Sales Director: Managing Director: Sales Manager: General Manager - Power: Finance Director: Procurement Manager: Director: Director: Managing Director: Finance Director: Sales Director: Managing Director: Sales Manager: Finance Director: Procu...

Have regex ignore new lines and just match on a whole large string?

I have this string here: CREATE UNIQUE INDEX index555 ON SOME_TABLE ( SOME_PK ASC ); I want to match across the multiple lines and match the SQL statements (all of them, there will be many in 1 large string)... something like this, however I am only getting a match on CREATE UNIQUE INDEX index555 ON (CREATE\s.+;) note:...

Help with Regex in PHP

Let's assume I do preg_replace as follows: preg_replace ("/<my_tag>(.*)<\/my_tag>/U", "<my_new_tag>$1</my_new_tag>", $sourse); That works but I do also want to grab the attribute of the my_tag - how would I do it with this: <my_tag my_attribute_that_know_the_name_of="some_value">tra-la-la</my_tag> ...

Regex for valid SI units (International System of Units)

I am looking for a regex to check for valid SI unit input in an http form. So for example, kg/m^3 would be valid for density or m/s^2 for acceleration. It seems like the kind of problem that may have been solved in some open library; or there may be a clever way to do it starting with a limited set of base units. It is for use i...

Regexp Question - Negating a captured character

I'm looking for a regular expression that allows for either single-quoted or double-quoted strings, and allows the opposite quote character within the string. For example, the following would both be legal strings: "hello 'there' world" 'hello "there" world' The regexp I'm using uses negative lookahead and is as follows: (['"])(?:(?!\1...

Why does this regex, using "not" & a backref, require a lazy match?

When using the not ^ operator in combination with a back reference, why do I need to use a lazy match? It seems like the not should break the match. For example: <?php preg_match('/(t)[^\1]*\1/', 'is this test ok', $matches); echo $matches[0]; ?> Will output this test, instead of this t, in spite of the fact that the middle t does no...

what does the empty regex match in ruby?

following a RoR security tutorial (here), i wrote something along the lines of @@private_re = // def secure? action_name =~ @@private_re end the idea is that in the base case, this shouldn't match anything, and return nil. problem is that it doesn't. i've worked around for the time being by using a nonsensical string, but i'd like t...

perl - regex help parsing hostname from log

I need help with my regex to grab my host information from this logfile: Tue Aug 24 10:22:14 2010: test1.colo_lvm:check:INFO: host=test1.dom.colo.name.com Tue Aug 24 10:22:14 2010: test1.colo_lvm:check:INFO: "/home/bin64"/admin --user="foo-bar" --password="*****" --host="test1.dom.colo.name.com" --port="9999" --socket="/tmp" variable...

shell command: need help about a regex match

I have a sentence that I want to write a shell command to grep it from a text: The sentence is: self.timeout=2.0 However, as this is a part of code from a file. so it this sentence could also be self.timeout = 2.0 or self.timeout =2.0 or self.timeout = 8.0 that is: there may be blanks besides "=", and the value of self.timeou...

PHP: Add Unique ID + Order ID for each word what starts with @

I need to add an Order ID + Unique ID for each word what starts with @. For example I have a string like this: Just @do @it and @do @it. I want to preg_replace #(\@)+([^\s]+)#i to this: Just <div id="1+Unique ID">@do</div> <div id="2+Unique ID">@it</div> and <div id="3+Unique ID">@do</div> <div id="4+Unique ID">@it</div>. ...

regex 'literal' meaning in regex

is there a way to treat a section of your regex string 'as is'? I.e. I want to match for the literal pattern: "[^*..@/w$[{" in some text (exaggerated example, but you see what I mean)... Can I just enclose the whole bit in something? ...

Regex: Finding the nth match

I am trying to write a regex to match the nth match. As I am new to regex please help me in solving this. Input: DECLARE numerator NUMBER; BEGIN SELECT x, y INTO numerator, denominator FROM result_table, secondTable WHERE sample_id = 8; delete from xyz where id=17; Match first WHERE or match second WHERE. Also please suggest me som...

Sinatra app running on Heroku has RegexpError

My sinatra app runs fine locally but when I push it to heroku it crashes and I get this error RegexpError - undefined (?...) sequence: /(?<=(LIST ALL SELECTED ))\w/: The line of code where the occurs is match = data.match('(?<=(LIST ALL SELECTED ))\w')[0] What I am trying to do is capture the next letter directly after 'LIST ALL S...

Need help to understand the folowing regex.

i wrote a regex, but it doesn't work as i expect. Take a look please preg_match_all("/([\.\:]?)(.{0,65}?[^\s]*".preg_quote($word)."[^\s]*.{0,65})/siu",$content,$matched); [^\s]*".preg_quote($word)."[^\s]// this part match the whole word, if it contain the keyword, for example it match keyword if i search for wor keyword. .{0,65}?...

Grubers new and improved URL recognising regex

Hi, I've been trying to use grubers latest url matching regex in a php project. To test it I threw together something very simple: $regex = "(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:"'.,<>?...

How to replace five digits from a string?

How to replace five digits from a string? Possibly a solution in Regexes, my regular expression skills are not so strong. string ort = "42671 VÄSTRA FRÖLUNDA"; ...

Help with regex - email address matching

I have the following regex which suppose to match email addresses: [a-z0-9!#$%&'*+\\-/=?^_`{|}~][a-z0-9!#$%&'*+\\-/=?^_`{|}~.]{0,63}@[a-z0-9][a-z0-9\\-]*[a-z0-9](\\.[a-z0-9][a-z0-9\\-]*[a-z0-9])+$. I have the following code in AS3: var mails:Array = str.toLowerCase().match(pattern); (pattern is RegExp with the mentioned regular exp...

Javascript Regex - Insert word (hit)

Hi, is it possible to insert the word that was found into the replace ? $(function() { content = 'hallo mein name ist peter und ich komme aus berlin. Und du?'; words = 'mein na,berlin' words = words.replace(/,/,'\|'); words = words.replace(/\s/,'\\s'); regex = new RegExp(words,'gi'); content = content.replac...

using backreferences regex in sed

I would like to remove multiple spaces in a file with a single character. Example cat kill rat dog kill cat I used the following regex, which seemed to matched in http://www.regexpal.com/ but wasn't working in sed. ([^ ])*([ ])* I used the sed command like so: sed s/\(\[\^\ \]\)*\(\[\ \]\)*/\$1\|/g < inputfile I ...

Reg ex validation on UTF8 / multi byte 'language' characters (inc chinese etc) but not special characters such as {/*

Hi, Using PHP / Mysql all encoded up as UTF we have recently had to start capturing non-Latin characters such as Chinese etc. We have php validation that checks on string length and alpha numeric such as if (!ereg("[[:alnum:]]{2,}",$_POST['company_name'])) { //error code here } This is not working on multi byte chars. I understand ...