regex

alpha with space regex in cakephp

I have a user registration form and I only want the user to specify their first and last name (i.e. Donalg Doonsberry). If the user doesn't provide their name in this fashion, the input will be rejected. I thought something like this would work for my regex user validation in cakephp: 'name'=>array('Name has to be comprised of letter...

how to replace last occurence of a word in javascript?

for example: var str="<br>hi<br>hi"; to replace the last(second) <br>, to change into "<br>hihi" I tried: str.replace(/<br>(.*?)$/,\1); but it's wrong. What's the right version? ...

How can I efficiently handle multiple Perl search/replace operations on the same string?

So my Perl script basically takes a string and then tries to clean it up by doing multiple search and replaces on it, like so: $text =~ s/<[^>]+>/ /g; $text =~ s/\s+/ /g; $text =~ s/[\(\{\[]\d+[\(\{\[]/ /g; $text =~ s/\s+[<>]+\s+/\. /g; $text =~ s/\s+/ /g; $text =~ s/\.*\s*[\*|\#]+\s*([A-Z\"])/\. $1/g; # replace . **** Begin or . #### B...

How can I write a regular expression to capture links with no link text?

How can I write a regular expression to replace links with no link text like this: <a href="http://www.somesite.com"&gt;&lt;/a&gt; with <a href="http://www.somesite.com"&gt;http://www.somesite.com&lt;/a&gt; ? This is what I was trying to do to capture the matches, and it isn't catching any. What am I doing wrong? string pattern ...

Javascript Regex and Submatches

Why do javascript sub-matches stop working when the g modifier is set? var text = 'test test test test'; var result = text.match(/t(e)(s)t/); // result: ["test", "e", "s"] the above works fine... [1] is e and [2] is s... perfect var result = text.match(/t(e)(s)t/g); // ["test", "test", "test", "test"] the above it screwed... it ig...

Python regular expression implementation details

A question that I answered got me wondering: How are regular expressions implemented in Python? What sort of efficiency guarantees are there? Is the implementation "standard", or is it subject to change? I thought that regular expressions would be implemented as DFAs, and therefore were very efficient (requiring at most one scan of the...

return only Digits 0-9 from a String

I need a regular expression that I can use in VBScript and .NET that will return only the numbers that are found in a string. For Example any of the following "strings" should return only 1231231234 123 123 1234 (123) 123-1234 123-123-1234 (123)123-1234 123.123.1234 123 123 1234 1 2 3 1 2 3 1 2 3 4 This will be used in an email pa...

Python regex question: stripping multi-line comments but maintaining a line break

Hello, I'm parsing a source code file, and I want to remove all line comments (i.e. starting with "//") and multi-line comments (i.e. /..../). However, if the multi-line comment has at least one line-break in it (\n), I want the output to have exactly one line break instead. For example, the code: qwe /* 123 456 789 */ asd should ...

unix regex for adding contents in a file

i have contents in a file like asdfb ... 1 adfsdf ... 2 sdfdf .. 3 I want to write a unix command that should be able to add 1 + 2 + 3 and give the result as 6 From what I am aware grep and awk would be handy, any pointers would help. ...

Parsing a string containing escaped characters using Java

Hello I wonder if someone could help me figure out how to parse a string having the following format: ;field1-field2-fieldN;field1-field2-fieldN; Each record is delimited by ';' and each field within a record is delimited by '-'. The complication is that the individual fields may contain escaped delimiter characters like so "\;" or "...

Regex solution for Objective-C

What is the best method for using Regular Expressions within Objective-C? There seems to be some open source project that provide regex support, can any one recommend one? Also I looked at NSPredicate, can anyone suggest any regex examples? Background: I want use regex mainly for validation, IP's, email addresses, internal ID's etc ...

Regex - Match ( only ) words with mixed chars

Hi all! :) i'm writing my anti spam/badwors filter and i need if is possible, to match (detect) only words formed by mixed characters like: fr1&nd$ and not friends is this possible with regex!? best regards! ...

Returning ordinal positions of regex matches in the original string

For fun, I'm developing a utility that will take an input string and a regex and will color highlight all matches of the regex in the original string, alike the Find function in Firefox or IE 8, and some popular browsers. I am using C#. Does any member of the System.Text.RegularExpressions namespace return the ordinal positions of the m...

How to remove space and restrict special chars using jquery?

I am creating a signup form in my website. I want to implement some checkup with username, which are username can't have any space, username can't have any special characters other than dot (.) as gmail is doing in thier signup form. I am using jQUERY in my app, can anyone tell me how to implement above listed two checkups using jqu...

[RegEx] Format all IP-Addresses to 3 digits

Hi I'd like to use the search & replace dialogue in UltraEdit (Perl Compatible Regular Expressions) to format a list of IPs into a standard Format. The list contains: 192.168.1.1 123.231.123.2 23.44.193.21 It should be formatted like this: 192.168.001.001 123.231.123.002 023.044.193.021 The RegEx from http://www.regextest...

Regex to strip BBCode

I need a regular expression to strip out any BBCode in a string. I've got the following (and an array with tags): new RegExp('\\[' + tags[index] + '](.*?)\\[/' + tags[index] + ']'); It picks up [tag]this[/tag] just fine, but fails when using [url=http://google.com]this[/url]. What do I need to change? Thanks a lot. ...

Regex optimisation - escaping ampersands in java

I need to replace all & in a String that isnt part of a HTML entity. So that the String "This & entites &gt; & &lt;" will return "This &amp; entites &gt; &amp; &lt;" And I've come up with this regex-pattern: "&[a-zA-Z0-9]{2,7};" which works fine. But I'm not very skilled in regex, and when I test the speed over 100k iterations, it uses...

Match overlapping patterns with capture using a MATLAB regular expression

I'm trying to parse a log file that looks like this: %%%% 09-May-2009 04:10:29 % Starting foo this is stuff to ignore %%%% 09-May-2009 04:10:50 % Starting bar more stuff to ignore %%%% 09-May-2009 04:11:29 ... This excerpt contains two time periods I'd like to extract, from the first delimiter to the second, and from the second to the...

Zend Route Regex Reverse problem with forward slashes

Hi I have a problem with reverse for regex routes, my config file is below: routes.route1.type = "Zend_Controller_Router_Route_Regex" routes.route1.route = "([^\,]+)([^p]*)(?:\,page_[0-9]+)?\.html" routes.route1.defaults.controller = "index" routes.route1.defaults.action = "find" routes.route1.map.1 = "url_path" routes.route1.map.2 = "u...

PHP RegEx for "Website Name"

Duplicate: PHP validation/regex for URL My goal is create a PHP regex for website name. The regex is for a lead gathering form and should accept any legit kind of website name syntax that someone might enter. After an exhaustive search, I'm surprised that I can't find one out there. Here are the regex matches that I'm looking for: ...