regex

preg_match_all returning only one match

Hi, I'm a PHP newbie. I'm trying to use preg_match_all function in the below program to find all subjects with their marks, but I'm getting only one match. I have been struggling with this for 5 hours. Can someone help me in figuring out whats wrong? Thanks in advance. <?php $semArray="<B>STUDENTS NAME (7ab05cs001) </B><br><br><br><br>...

php - parse friendly url

Hi, I have url like this /cp/foo-bar/another-testing how to parse it with the pattern /cp/{0}-{1}/{2} results will be 0:foo 1:bar 2:another-testing I need a global solution to parse all kind of url with a pattern like that. I mean using {0}, {1} flag. ...

Phone Number Regular Expression (Regex) in Python

Dive into python gives an amazing little tutorial on creating a regular expression for phone numbers (http://diveintopython.org/regular_expressions/phone_numbers.html) The final version comes out to look like: phone_re = re.compile(r'(\d{3})\D*(\d{3})\D*(\d{4})\D*(\d*)$', re.VERBOSE) This works fine for almost all examples I can come ...

How can i find a parent id in Zend Framework?

I have a site with next structure. We have car's brands. If we click on link with brand, list with models of this model should be open. The url like this: http://example/brand/4. All good. But i don't know, how find a brand id. I need this, because i should know, where the models must be open (under what brand). I am using Router. Can ...

PHP server-side validation regular expression match

Hey guys, I have the following part of a validation script: $invalidEmailError .= "<br/>&raquo;&nbsp;You did not enter a valid E-mail address"; $match = "/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/"; That's the expression, here is the validation: if ( !(preg_match($match,$email)) ) { $errors .= $invalidEmailError; // checks...

Grab product code from a url, do I need regex for this?

A url looks like: http://www.example.com/cgi-bin/blahblah?&amp;PC=abd23423&amp;uy=020 I need to extract the value: abc23423 I tried this regex but its not working: rx = re.compile(r'PC=(\w*)&uy=') I then I did: pc = rx.search(url).groups() but I get an error: attribute error: nonetype object has no attribute groups. ...

Regex to extract substring, returning 2 results for some reason

I need to do a lot of regex things in javascript but am having some issues with the syntax and I can't seem to find a definitive resource on this.. for some reason when I do: var tesst = "afskfsd33j" var test = tesst.match(/a(.*)j/); alert (test) it shows "afskfsd33j, fskfsd33" I'm not sure why its giving this output of original a...

Get all occurences of the search pattern

I try to get all occurences of a pattern from a file, but currently I fail if there is more than one occurence per line. Sample line in file: lorem ipsum foo="match1" lorem ipsum foo="match2" lorem ipsum The output I want: match1 match2 I tried getting this using sed: sed -ne 's/^.*foo="\([^"]*\)".*$/\1/p' With this expression ...

php - regex pattern

I need to use a regex pattern , but what is the right php "decode" . my pattern is "similar" to BBcode i.e. ['something'] the 'something' could be "any length" but realistically I doubt not more than 10 chars/numbers. What is the correct php syntax to "unscrambe" i.e. if ($row->xyz =['something'] ): do this else: do that en...

Are regular expressions used to build parsers?

This is just a question out of curiosity since I have been needing to get more and more into parsing and using regex lately.. it seems, for questions I come across in my searches regarding parsing of some sort, someone always ends up saying, when asked something relating to regex, "regex isn't good for that, use such and such parser inst...

extract long/lat from a string

HI, I have a string that could contain a longitude and a latitude. The string could contain anything but if it does contain a lon/lat then I want to extract it using php. I think I need a regular expression but I don't have a clue how to get that out. The string could contain anything: a random string dfdff33338983 33.707352,-116.27279...

Get substring from string with a regex

How can I get my four numbers from strings with this format: Some text with 1 numbers (10/ 100) some other text... From -10°C to 50°C Some other text with 2 numbers (10/ 100) some other text... From -11°C to -2°C Some other text with -30 numbers(100/ 1001) some other text... From 2°C to 12°C First two numbers are in the brackets and ...

How to use regex to extract values from a string.(PHP)

I have a string like this \"access_token=103782364732640461|2.ZmElnDTiZlkgXbT8e34Jrw__.3600.1281891600-10000186237005083013|yD4raWxWkDe3DLPJZIRox4H6Q_k.&expires=1281891600&secret=YF5OL_fUXItLJ3dKQpQf5w__&session_key=2.ZmElnDTiZlkgXbT8e34Jrw__.3600.1281891600-10000186237005083013&sig=a2b3fdac30d53a7cca34de924dff8440&uid=10000186237005083...

Will this RegEx match any Stack Exchange site?

I have made this RegEx: /http:\/\/(.+)?\.?(stackoverflow|superuser|serverfault|stackapps|stackexchange)\.com\/questions\/([0-9]+)\/?.*/i It needs to match any Stack Exchange website's question. Is this the right RegEx? I have tested it and it works, but I've not tested it on all beta-sites and since I know I'm Satan in the RegEx world...

What is the regular expression to get a token of a URL?

Say I have strings like these: bunch of other html<a href="http://domain.com/133742/The_Token_I_Want.zip" more html and stuff bunch of other html<a href="http://domain.com/12345/another_token.zip" more html and stuff bunch of other html<a href="http://domain.com/0981723/YET_ANOTHER_TOKEN.zip" more html and stuff What is the regular exp...

regular expressions using java.util.regex API- java

How can I create a regular expression to search strings with a given pattern? For example I want to search all strings that match pattern '*index.tx?'. Now this should find strings with values index.txt,mainindex.txt and somethingindex.txp. Pattern pattern = Pattern.compile("*.html"); Matcher m = pattern.matcher("input.html"); This co...

Regular Expression for password

Hi, I'm not really good at regular expressions. I need to do the following to validate if a password entered by the user is correct or not. Criteria: Must contain at least one number Must contain at least one letter from A-Z or a-z (case does not matter as long as they enter is a letter). The password must be a minimum of 8 character...

Django URL regex problem

I don't know why i can't match url when url is "http://localhost:8000/home/CPM%201.6.1001" since i want pass parameter CPM 201.6.1001 from my template to urls thanks:) urls.py urlpatterns = patterns('', (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), (r'^home/(?P<build>\[^/]+)/$'...

regular expression that matches a string where the string DOESNT lead with 'username'

So I'm trying to write a regex and get it to match the string ONLY if the string doesn't start with the string 'username' I tried something like ^([^username])... but that matches strings where the string doesn't start with any of those letters. Any help would be appreciated! ...

PHP passing variables to Perl, having issues with using spaces between variables method, is there another, better way?

I find myself needing to use Perl more and more since PHP's regular expressions leave me wondering what is going on half the time as they simply don't respond as they should (as they do when I use Perl, for example)... i had been using this method to call perl (before i started trying to do this with regular expressions).. passing in a r...