regex

How to detect identical part(s) inside string?

I try to break down the http://stackoverflow.com/questions/2711961/decoding-algorithm-wanted question into smaller questions. This is Part I. Question: two strings: s1 and s2 part of s1 is identical to part of s2 space is separator how to extract the identical part(s)? example 1: s1 = "12 November 2010 - 1 visitor" s2 = "6 July 201...

javascript regex pattern concatenate with variable

How to create regex pattern which is concatenate with variable, something like this: var test ="52"; var re = new RegExp("/\b"+test+"\b/"); alert('51,52,53'.match(re)); Thanks ...

Regular expression and newline

Hello guys, I have such text: <[email protected]> If you do so, please include this problem report. <[email protected]> You can delete your own text from the attached returned message. The mail system <[email protected]>: connect to *.net[82.*.86.*]: Connection timed out I have to parse email from ...

Why doesn't Python's `re.split()` split on zero-length matches?

One particular quirk of the (otherwise quite powerful) re module in Python is that re.split() will never split a string on a zero-length match, for example if I want to split a string along word boundaries: >>> re.split(r"\s+|\b", "Split along words, preserve punctuation!") ['Split', 'along', 'words,', 'preserve', 'punctuation!'] ins...

Find Javascript Code inside String

Greetings friends, I am developing a web application that will allow the customer to enter a personalized message, which will then be converted to HTML. Well, the problem is that I can not allow the insertion of Javascript code. So I need a method that filters the text, searching for and remove it. I think the regular expressions to so...

Javascript search and replace sequence of characters that contain square brackets

Hello all I'm trying to search for '[EN]' in the string 'Nationality [EN] [ESP]', I want to remove this from the string so I'm using a replace method, code examaple below var str = 'Nationality [EN] [ESP]'; var find = "[EN]"; var regex = new RegExp(find, "g"); alert(str.replace(regex, '')); Since [EN] is identified as a character set...

Redirect visitor with .htaccess

Hi all, I've got an e-shop on a virtual server that's been used as a subdirectory for the last few years, but now I'm finally giving the VS it's own domain name. What I really need is visitors to the old URL to be transparently (and 301) redirected to the new URL with everything after /eshop/ maintained and apended to the new host. I.e...

Why doesn't this Regex work in .NET?

I want a regex that will verify that a string begins with a letter followed by some letters, numbers, or underscores. According to my EditPadPro regex parser the following test should pass. But it does not. Regex.IsMatch("Class1_1", @"^\w[\w|\d|_]*$").ShouldBeTrue(); What am I missing? ...

php array regular expressions

I am using regular expressions in php to match postcodes found in a string. The results are being returned as an array, I was wondering if there is any way to assign variables to each of the results, something like $postcode1 = first match found $postcode2 = second match found here is my code $html = "some text here bt123ab and an...

Does .NET Regex support global matching?

I haven't been able to find anything online regarding this. There's RegexOptions, but it doesn't have Global as one of its options. The inline modifiers list also doesn't mention global matching. In a nutshell, I've got a regex to parse something like --arga= "arg1" --argb ="arg2" into separate argument name/value pairs using thi...

Replace strings differently depending if is enclosed in braces or not.

I want to replace all instances of an specific words between braces with something else, unless it is written between double braces, while it should show as is it was written with single braces without the filter. I have tried a code but only works for the first match. The rest are shown depending of the first one: $foo = 'a {bar} b {{b...

PHP REGEX - text to array by preg_split at line break

Hi All! EDITED: need help on split Array array example: array ( [0] => :some normal text :some long text here, and so on... sometimes i'm breaking down and... :some normal text :some normal text ) ok, now by using preg_split( '#\n(?!s)#' , $text )...

Regex - how to match everything except a particular pattern

Hi, I'm using Apache and I want to redirect all received request to the ssl virtual host. So I have the following line in the regular http virtual host: RedirectMatch (.*) https://www.mydomain.com$1 which basicaly replace $1 by everything. It works perfectly. But now, I need to access a particular CGI that cannot be on the SSL vi...

Remove dash from a phone number

What regular expression using java could be used to filter out dashes '-' and open close round brackets from a string representing phone numbers... so that (234) 887-9999 should give 2348879999 and similarly 234-887-9999 should give 2348879999. Thanks, ...

Regular Expression question

Hi, For an academic assignment, I need to make a regular expression to match a word with the following specifications: Word length >= 1 and <= 8 Contains letters, digits, and underscore First digit can only be a letter Word is not A,X,S,T or PC,SW I tried this regex but can't continue (My big problem is to make the word not equal to...

Finding Links on a Webpage with Java

Using Java have the source code of a webpage stored in a string. I want to extract all the urls in the source code and output them. I am awful with regex and the like and have no idea how to even approach this. Any help would be greatly appreciated. ...

any excellent Python 're' tutorial

I read through the official regular expression howto which wasn't gentle enough for me. Is there anything better/easier out there? ...

How to find all Chinese text in a string using python?

I needed to strip the Chinese out of a bunch of strings today and was looking for a simple python regex. Any suggestions? ...

How to convert a string into a Point?

I have a list of strings of the format "x,y". I would like to make them all into Points. The best Point constructor I can find takes two ints. What is the best way in C# to turn "14,42" into new Point(14,42);? I know the Regex for doing that is /(\d+),(\d+)/, but I'm having a hard time turning those two match groups into ints in C#. ...

How can I remove repeated characters but leave two of them?

If there are more than 2 characters "Hiiiiiii My frieeend!!!!!!!" I need to be reduced to "Hii My frieend!!" Please undestand that in my language there are many words with double chars. Thnx in advance kplla ...