regex

regexp split string by commas and spaces, but ignore the inside quotes and parentheses

I need split string by commas and spaces, but ignore the inside quotes, single quotes and parentheses $str = "Questions, \"Quote\",'single quote','comma,inside' (inside parentheses) space #specialchar"; so that the resultant array will have [0]Questions [1]Quote [2]single quote [3]comma,inside [4]inside parentheses [5]space [6]#spec...

REGEXP to convert any 3 chars or less word to wordVVV

I am trying to convert any occurrence of a word with 3 chars or less to the same word with the string VVV attached to it. Example: for -> forVVV I am using none Latin chars (UTF8), hence the MB. What I have is: $pattern='\b[.{1,6}]\b'; $text=mb_ereg_replace($pattern,'\0VVV',$text,'me'); What am I missing? Here is a case study, see ...

Regex matching too much

(\[(c|C)=)(#?([a-fA-F0-9]{1,2}){3})\](.*)\[/(c|C)\] I want this expression to match text like: "This is [c=FFFFFF]white text[/c] and [C=#000]black text[/C]." It do match one BB-code alone, but if there are more after each other (like in the example), it will create a match (1 match) of both BB-code-sequences. (from [c=FFFFFF]wh... to ...

.NET regular expression - ? isn't working (like I think it should)

I have an HTML page (it's out of an internal address book application) and I'm trying to match both the field name and field value out of a table. The regular expression I've cooked up so far is "href.*?>(.*?)<\\/a.*>(.*?)<\\/span" which matches most of the keys and values just fine. The problem is that some of the values are also l...

Need Javascript Regex Replace to wrap certains words with <a...>

We have a database where every table name starts with WW. I want to display an SQL on a web page, but wrap each table name with a link. For example: "select * from wwx_something where ..." Should be transformed into: "select * from <a href='/table/wwx_something/'>wwx_something</a> where ..." There might be several tables, of course...

Find out how many times a regex matches in a string in Python

Is there a way that I can find out how many matches of a regex are in a string in Python? For example, if I have the string "It actually happened when it acted out of turn." I want to know how many times "t a" appears in the string. In that string, "t a" appears twice. I want my function to tell me it appeared twice. Is this possible? ...

C# Find/Replace Credit Cards In XML String

I receive rather long XML strings as output from a third party and some of the fields represented in the XML may contain credit card numbers. I do not know the node/element/attribute names ahead of time. What would be the simplest method for finding and replacing card numbers with a placeholder in C#? String functions? Regex? Edit: ...

use preg_replace to replace character unless an escape character precedes

Hi all... i'm trying to do the following hope there's a reg_ex expert around to shed some light. I need to replace the character [ in my code and make it a {. But there is cases where the [ needs to remain a [ and not change. So the way i figured it is i need to use the preg_replace("[", "{", $string); function with a suitable regula...

Java regex matching to replace substrings

How can I replace all occurences of java substrings like stuff="-9888777666" , stuff="123", with the substring stuff="0"? The double quotes are actually a part of the string. ...

Can someone explain this regex

I know this is a pretty basic regex, could someone explain what it is doing please? ^[^@]+@[-a-z0-9.]+$ ...

PHP maybe regex

OK, so I have a new project with me, it is basically on solving logical and reasoning type of problems. Like in maths you are given a figure and asked how many triangles are in it. What I have to do is. User enters a code and a word. example word -> example code -> aesxxasskmpaalee here if we remove certain characters, we can form exa...

Limit user input to allowable comma delimited words with regular expression using javascript

I want to force the user to enter any combination of the following words. the words need to be comma delimited and no comma at the beginning or end of the string the user should only be able to enter one of each word. Examples admin basic,ectech admin,ectech,advanced basic,advanced,admin,ectech my attempt ^((basic|advanced)|admin|ec...

Java regex to remove all trailing numbers?

I want to remove any numbers from the end of a string, for example: "TestUser12324" -> "TestUser" "User2Allow555" -> "User2Allow" "AnotherUser" -> "AnotherUser" "Test123" -> "Test" etc. Anyone know how to do this with a regular expression in Java? ...

Help simplifying this Regular Expression pattern

Hello SO: I have this Regular Expression that matches the following strings: <!-- 09-02-2009 ---> <!-- 09-02-2009 12:00:00 ---> <!-- 09-02-2009 12:00:00 A ---> <!-- 09-02-2009 12:00:00 AM ---> Here is the pattern: <!-- (?<month>\d{2}?)-(?<day>\d{2}?)-(?<year>\d{4}?)(?:(?: ?\d{2}:?){3}?(?: ?[aApP][mM]?)?)? ---> updated pattern, per...

Regexp for extracting a mailto: address

I'd like a reg exp which can take a block of string, and find the strings matching the format: <a href="mailto:[email protected]">....</a> And for all strings which match this format, it will extract out the email address found after the mailto:. Any thoughts? This is needed for an internal app and not for any spammer purposes! ...

Using PHP PCRE to fetch div content

Hi, I'm trying to fetch data from a div (based on his id), using PHP's PCRE. The goal is to fetch div's contents based on his id, and using recursivity / depth to get everything inside it. The main problem here is to get other divs inside the "main div", because regex would stop once it gets the next </div> it finds after the initial <d...

PHP and regular expressions: how to get the character count of all characters in a string containing HTML, but measuring only 20 visible words?

I am working on a WordPress site where one of the pages lists excerpts about corporate clients. Let's say I have a web page where the visible text looks like this: "SuperAmazing.com, a subsidiary of Amazing, the leading provider of integrated messaging and collaboration services, today announced the availability of an enhanced version...

calculate user inputed time with Python

I need to calculate (using python) how much time a user has inputed, whether they input something like 3:30 or 3.5. I'm not really sure what the best way to go about this is and I thought I'd ask for advice from the experts. === Edit ================== To specify more clearly, I want the user to input hours and minutes or just minut...

Notepad++ Regular expression find and delete a line

Hi, I am trying to find and delete a line using Notepad++ I need to find lines in this file (UNIX Format) that match the string '#RedirectMatch Permanent' and delete that line. Does anyone know how to do this using Notepad++ Find and Replace? Thanks and Kind Regards, ...

PHP regex behaves differently on different versions or different OS's

Hello, I'm using two different version of php on two different OS's. One is 5.2.9 running on windows (wamp). One is 5.2.6 running on CentOS 5 (lamp). Regex involving group names works on the Windows one but not on the CentOS. Such example would be /^field_(?<myname>.+)/ Is this an OS issue? Or one with the way PHP was build? Thank...