regex

How to modify this regex expression to accept hyphens?

I have the following Regex (in PHP) that I am using. '/^[a-zA-Z0-9&\'\s]+$/' It currently accepts alpha-numerics only. I need to modify it to accept hyphens (i.e. the character '-' without the quotes obviously) as well. So it will accept strings like 'bart-simpson' OR 'bond-007' etc. Can anyone explain how to modiy the pattern? ...

Regular Expression to remove Div tags

Hi, I have a div tag, nested with many span and div tags inside it. now i want a regular expression in javascript which will strip the div and the content inside it. thanks in advance.. ...

How to detect what allowed character in current Regular Expression by using JavaScript?

In my web application, I create some framework that use to bind model data to control on page. Each model property has some rule like string length, not null and regular expression. Before submit page, framework validate any binded control with defined rules. So, I want to detect what character that is allowed in each regular expression...

splitting text with javascript match

for below code var str = "I left the United States with my eyes full of tears! I knew I would miss my American friends very much.All the best to you"; var re = new RegExp("[^\.\?!]*(?:[\.\?!]+|\s$)", "g"); var myArray = str.match(re); and This is what I am getting as a result myArray[0] = "I left the United States with my eyes full ...

How can I write a Perl one-liner for a Makefile so I can translate a literal \n to a newline?

I need to escape \n so on output I really get newline or tab $ perl -p -e 's/e/a/ge' now I want each e to be substituted with \n $ perl -p -e 's/e/\n/ge' but even \n gives me an error. this was a simplified example. In real script(makefile) I have substitute := perl -p -e 's/@([^@]+)@/defined $$ENV{$$1} ? $$ENV{$$1} : $$1/ge' ...

Regex not working in one case

I have a string with the following information. Obabikon, ON 49°10′N 94°10’W 2278 km N69°W I have a regex search as follows: String LongPattern = @"(~)?([0-9\?])+°([0-9\?])*′[EWO]"; return FindPattern(source, LongPattern); It should be finding the <94°10’W> But is it not. This regex is working for the rest of my data with out any p...

Linux - Want To Check For Possible Duplicate Directories (Probably RegEx Needed)

Hi, I have a directory which contains several directories as follows: /Music/ /Music/JoeBlogs-Back_In_Black-1980 /Music/JoeBlogs-Back_In_Black-(Remastered)-2003 /Music/JoeBlogs-Back_In_Black-(ReIssue)-1987 /Music/JoeBlogs-Thunder_Man-1947 I want a script to go through and tell me when there are 'possible' duplicates, in the example ...

Regex to check if exact string exists including #

New question As suggested by Asaph in previous question: Regex to check if exact string exists I am looking for a way to check if an exact string match exists in another string using Regex or any better method suggested. I understand that you tell regex to match a space or any other non-word character at the beginning or end of a string...

Replacing values using preg_replace

I have a Joomla plugin (not important in this context), which is designed to take an input with a load of numbers (within a paragraph of text) and replace them with a series of s. My problem is that I need to do a preg_replace on my $article->text, but I don't know how to then apply the changes to the matched terms. I've seen the preg_r...

Help with regex in javascript.

Whatever string is given I have to see if there is exactly one space after and before =, If it is more than one space in either side I have to reduce that to one and if there is none, I have to insert one. How should I do that ? String can contain anything. Thanks ...

String regex matching in Erlang

How would I do regex matching in Erlang? All I know is this: f("AAPL" ++ Inputstring) -> true. The lines that I need to match "AAPL,07-May-2010 15:58,21.34,21.36,21.34,21.35,525064\n" In Perl regex: ^AAPL,* (or something similar) In Erlang? ...

How to fetch number of the text?

I have the text like "It's the 145 of 13221 items". I need to fetch all the number("145 and 13221") of text on one time. I want to use regex to do this. What is the regex like? "\d+" is not work fine. ...

PHP Regex Question

Hi, I am developing an application using PHP but I am new to regular expressions, I could not find a solution to my problem. I want to replace all occurences of #word with a link, i have written a preg_match for this: $text=preg_replace('~#([\p{L}|\p{N}]+)~u', '<a href="/?aranan=$1">#$1</a>', $text); The problem is, this regular expr...

Help using preg_match for phone numbers

how would i write an if statement that would find phone numbers and store them to a variable. Here is what i have so far but its not working. if (preg_match('/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[...

Regular expression to match one of two video ID's in a Google Video URL

I need to grab the video ID from a Google Video URL. There are two different types of URLs that I need to be able to match: http://video.google.com/videoplay?docid=-3498228245415745977# where I need to be able to match -3498228245415745977 (note the dash; -), and video.google.com/videoplay?docid=-3498228245415745977#docid=2728...

Checking if language is set in url with regex

I have am working on a multi language file. My urls look something like this: http://www.mydomain.com/en/about/info http://www.mydomain.com/nl/about/info Now I use a small regex script that redirect the user when they use a link without language. The script looks like this: preg_match('~^/[a-z]{2}/~', $_SERVER['REQUEST_URI'] This f...

Regular Expression Help

Looking for some help with a Regular Expression to do the following: Must be Alpha Char Must be at least 1 Char Must NOT be a specific value, e.g. != "Default" Thanks for any help, Dave ...

asp.net regex to find anchor tags and replace their url

Hi -i'm trying to find all the anchor tags and appending the href value with a variable. for example <a href="/page.aspx">link</a> will become <a href="/page.aspx?id=2"> <A hRef='http://www.google.com'&gt;&lt;img src='pic.jpg'></a> will become <A hRef='http://www.google.com?id=2'&gt;&lt;img src='pic.jpg'></a> I'm able to match all th...

Find and replace question regarding RegEx.Replace

Hello, I have a text file and I want to be able to change all instances of: T1M6 to N1T1M6 The T will always be a different value depending on the text file loaded. So example it could sometimes be T2M6 and that would need to be turned into N2T2M6. The N(value) must match the T(value). The M6 will always be M6. Another example:...

How to use linux csplit to chop up massive XML file?

Hi everyone, I have a gigantic (4GB) XML file that I am currently breaking into chunks with linux "split" function (every 25,000 lines - not by bytes). This usually works great (I end up with about 50 files), except some of the data descriptions have line breaks, and so frequently the chunk files do not have the proper closing tags - an...