regex

String operation in PHP

I'm now dealing with uri like /page.html?k1=1&k2=2 $str = preg_replace('/[&\?]' . $k . '=[^&]*/',"",$str); The above aims to delete $k related part in uri,but will also delete ? wrongly. How to do the right thing? ...

Remove composed words

I have a list of words in which some are composed words, in example palanca plato platopalanca I need to remove "plato" and "palanca" and let only "platopalanca". Used array_unique to remove duplicates, but those composed words are tricky... Should I sort the list by word length and compare one by one? A regular expression is the an...

Regex slow on Windows Server 2008

Hi I have a situation where my regular expressions compile extremely slowly on Windows Server 2008. I wrote a small console application to highlight this issue. The app generates its own input and builds up a Regex from words in an XML file. I built a release version of this app and ran it both on my personal laptop (running XP) and ...

Python Regex "object has no attribute"

I've been putting together a list of pages that we need to update with new content (we're switching media formats). In the process I'm cataloging pages that correctly have the new content. Here's the general idea of what I'm doing: Iterate through a file structure and get a list of files For each file read to a buffer and, using...

Need help with regular expression to parse a string of e-mail addresses in C#

can someone write a regex in C# for me to verify the following emails ? [email protected];[email protected];[email protected];[email protected]; every email addresses are seperated with ";", and I have wrote the following regex: ^(([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9});)*$ when use this regex to match a strin...

help with a tag removal regex

I have strings in the form: "[user:fred][priority:3]Lorem ipsum dolor sit amet." where the area enclosed in square brackets is a tag (in the format [key:value]). I need to be able to remove a specific tag given it's key with the following extension method: public static void RemoveTagWithKey(this string message, string tagKey) { if ...

Regular Expression for UK Telephone Number

Hi, I want VB.NET regular expression for below format 7966-591739 I mean user must have to enter 4 numeric characters first then "-" and then 6 numeric characters after that optional for numeric as well as for characters. In my case user can also enter 7966-591739 ext 562 7966-591739 x 434 Please suggest! ...

Extracting matches from php regex

In perl regex we can extract the matched variables, ex below. # extract hours, minutes, seconds $time =~ /(\d\d):(\d\d):(\d\d)/; # match hh:mm:ss format $hours = $1; $minutes = $2; $seconds = $3; How to do this in php? $subject = "E:[email protected] I:100955"; $pattern = "/^E:/"; if (preg_match($pattern, $subjec...

Javascript - return string between square brackets

I need to return just the text contained within square brackets in a string. I have the following regex, but this also returns the square brackets: var matched = mystring.match("\\[.*]"); A string will only ever contain one set of square brackets, e.g.: Some text with [some important info] I want matched to contain 'some important ...

Searching for data within a string. Regular expressions?

I have some strings I need to scrape data from. I need a simple way of telling PHP to look in the string and delete data before and after the part I need. An example is: When: Sat 19 Sep 2009 22:00 to Sun 20 Sep 2009 03:00  I want to delete the "When: " and then remove the & and everything after it. Is this a Regex thing? Not...

Replacing specific non-printable characters in huge files from linux command line

I need to replace the ascii characters SOH and STX (start of header and start of text, ascii characters 1 and 2, respectively) in some really huge text files as quickly as possible... Is sed the way to go? What does that command look like? ...

Python Regular Expressions

How do I include an end-of-string and one non-digit characters in a python 2.6 regular expression set for searching? I want to find 10-digit numbers with a non-digit at the beginning and a non-digit or end-of-string at the end. It is a 10-digit ISBN number and 'X' is valid for the final digit. The following do not work: is10 = re.comp...

Is there an elegant way to do partial regex matches in Java?

What I need is to check whether a given string partially matches a given regex. For example, for the regex ab[0-9]c, the strings "a", "ab", "ab3", and "b3c" would "match", but not the strings "d", "abc", or "a3c". What I've been doing is the clunky a(?:b(?:[0-9](?:c)?)?)? (which only works for some of the partial matches, specifically ...

php regex failed, why?

The value is AbcDefg_123. Here is the regex: function checkAlphNum($alphanumeric) { $return = false; if((preg_match('/^[\w. \/:_-]+$/', $alphanumeric))) { $return = true; } return $return; } Should allow a-zA-Z0-9.:_-/ and space in any order or format and does need all but at least one character. EDIT: Sorry again...

Syntax regex to extract the source of an image

Ahoy there! I can't "guess" witch syntax should I use to be able to extract the source of an image but simply the web address not the src= neither the quotes? Here is my piece of code: function get_all_images_src() { $content = get_the_content(); preg_match_all('|src="(.*?)"|i', $content, $matches, PREG_SET_ORDER); foreach...

Use awk to add namespace to C# files

I have several C# classes where the namespace wasn't added to the file. A sample file looks like this (Test.cs): using System; using System.IO; public partial class MyTestClass { protected void MyTestVoid() { // Magic happens here } } As you can see there is no namespace declaration. I want the output to be: usin...

htaccess rewrite turn all "folders" into request variables, almost got it!

Here's what I have now: Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/([^/]+)(.*)$ /$3?$1=$2 [N,QSA] This turns www.any.com/x/20/y/30 into www.any.com/index.php?x=20&y=30 (while ignoring existing directories - thank you so much Gumbo!!) RewriteRul...

Regex Javascript 0-9a-zA-Z plus whitespace, commas etc

Hiya, Can anyone help me with this regex? I need something which will ALLOW: 0-9 a-z A-Z spaces hyphens apostrophes But disallow all other special characters. I've got this, but it's not working: "regex":"/^[0-9a-zA-Z/ /-'_]+$/", Thanks for any help! ...

What is a javascript regular expression for matching time in military (24 hour) format?

I would like a javascript regular expression that will match time using the 24 hour clock, where the time is given with or without the colon. For example, I would like to match time in the following formats: "0800", "23:45", "2345" but that would not match invalid times such as "34:68" or "5672" ...

php preg_match regex

Still having RegEx issues.. Need to match the following characters a-zA-z9-0 , . ' " ( ) _ - : (SPACE) Not all the values will have all these but could have them. I have everything withing but the parentheses, Single and Double Quoytes /^[\w. ,\/:_-]+$/ UPDATE: I got it working with this: "/^[\w. ,:()'\"-]+$/" $val_1 = "Abh acb 1...