Tag Archives: regex

Why is it that regex cannot match an XML element?

Questions: This article argues that regular expressions cannot match nested structures because regexes are finite automatons. He then offers a list of problems in which the answer states that the following cannot be solved using regexes: matching an XML element matching a C/VB/C# math expression matching a valid regex Since 2 & 3 can conceivably… Read More »

nginx rewrite regex min,max repetition

Questions: I am using this rewrite in NGINX. rewrite ^/test[^a-zA-Z0-9]{2}/?$ https://www.google.com permanent; // doesn’t work The server fails to start with I add the min {2} repetition in the regex. The server comes up when I remove that like here: rewrite ^/test[^a-zA-Z0-9]/?$ https://www.google.com permanent; // this works I have tried both {min,max} params. The error… Read More »

NGINX Regex location – Starts with X AND does not contain Y

Questions: I have the following location config: location ~ ^/(trucks|cars|planes|system|tools) { auth_basic “Restricted”; auth_basic_user_file /etc/nginx/htauth_file; proxy_set_header Host “server.lan”; proxy_set_header X-Real-IP $remote_addr; proxy_pass$request_uri; } When anyone makes requests to /trucks or /cars etc, I want them to be authenticated by the basic auth. But when anyone makes requests to /trucks?id=123 or /cars?id=124 then I want… Read More »

Nginx URL rewrite regex

Questions: I’ve switched over from Apache to Nginx. A very smooth and trouble free process, until I had to sort out a .htaccess file I have, and now I am stumped. I understand that Nginx does this differently and that this needs to be done in the config file (within a location /{code here} entry)… Read More »

Validating US phone number with php/regex

Questions: EDIT: I’ve mixed and modified two of the answers given below to form the full function which now does what I had wanted and then some… So I figured I’d post it here in case anyone else comes looking for this same thing. /* * Function to analyze string against many popular formatting styles… Read More »

Get the price of an item on Steam Community Market with PHP and Regex

Questions: I’m trying to use PHP to get the Steam Community Market price of an item. I take a url (for example : http://steamcommunity.com/market/listings/730/StatTrak%E2%84%A2%20P250%20%7C%20Steel%20Disruption%20%28Factory%20New%29) and then I download the content with file_get_contents(). I tried to use this : function getInnerHTML($string, $tagname, $closetagname) { $pattern = “/<$tagname ?.*>(.*)<\/$closetagname>/”; preg_match($pattern, $string, $matches); return $matches[1]; } Using getInnerHTML($str,… Read More »