regex

Regexp to search/replace only text, not in HTML attribute

Hello, I'm using JavaScript to do some regular expression. Considering I'm working with well-formed source, and I want to remove any space before[,.] and keep only one space after [,.], except that [,.] is part of a number. Thus I use: text = text.replace(/ *(,|\.) *([^ 0-9])/g, '$1 $2'); The problem is that this replaces also text i...

Match several times in RegexKitLite

I'm trying to get some info out of a document. I'm trying to match the info I need with regex, which matches 3 numbers within a string. It works fine, but it only matches the first occurance. I need it to match an unlimited number of times because I don't know how many times this string will occur. NSString *regex = @"String containing ...

preg_replace a specific pattern

I would like to use preg_replace to replace "* @license until */" with "testing". How can I do it? My text is the one below: /* * @copyright * @license * */ I hope everyone have understand my question correctly. ...

Specific .NET Regex Help

I need a .NET Regex that extracts the "field" and "width" values in the following string: <element attribute='{field}' attribute='{field,}' attribute='{ field }' attribute='{ field, 0 }' attribute='{field,0}' attribute='{ field, 10 }' attribute='{field,10}' attribute='{ field, 100 }' attribute='{field...

How can I extract/parse from this SOAP envelope using Ruby?

I am using a gem which uses soap/wsdlDriver. When I post I get back a SOAP response and am unable to easily parse it. This is the response I get back: #<SOAP::Mapping::Object:0x159e95faf098 {}id="27b907f8-da51-f611-ab02-4c5f88a8ec8 8" {}error=#<SOAP::Mapping::Object:0x159e95fae33c {}number="0" {}name="No Error" {}description="No Erro...

Regex to replace all ocurrences of a given character, ONLY after a given match.

For the sake of simplicity, let's say that we have input strings with this format: *text1*|*text2* so, I want to leave text1 alone, and remove all spaces in text2 This could be easy if we didn't have text1, a simple search and replace like this one would do: %s/\s//g but in this context I don't know what to do. I tried with somet...

Regular expression issue

Hello, may be this is newbie question, but I must ask it! In general I'm understand regular expressions, but I don't understand, why this one: ^.{8}[[:blank:]]{2} works on this line: prelink: /lib/libkeyutils-1.2.so: at least one of file's dependencies has changed since prelinking in this grep command: echo "prelink: /lib/libkeyut...

Regex to match words with only non-special characters

I'm trying to come up with a regex that will match only words that do not contain special characters. In the following string: one two:two three four five:five six I want to match one, three, four, and six only. I want to exclude the two:two and five:five. /[a-zA-Z]+/ matches these words, but it also matches "two", "two", "five" and "f...

Logical 'or' in Lua patterns?

Is it possible to achieve in Lua? local noSlashEnding = string.gsub("slash\\ending\\string\\", "\\|/$", "") -- noSlashEnding should contain "slash\\ending\\string" local noSlashEnding2 = string.gsub("slash/ending/string/", "\\|/$", "") -- noSlashEnding2 should contain "slash/ending/string" The point here is the no acceptance of logic...

Help with Regular Expression In PHP

I want to get an array of the following types of strings: data {string1} {string2} {string3} data I want to get an array whose values are string1/string2/strin3. How can I do this? ...

Java using regular expressions

I am working with resetting passwords. I need a way in java using regular expressions to reset the password so it cannot contain 4 consecutive characters from the previous password. ...

Concerns regarding potential Regex misuse?

Hi, I have the following regex: ^[a-zA-Z](.*)[a-zA-Z]$ on both the Javascript and PHP side that I have been using for validating a person's name and message fields on a contact form (no database interaction). It basically ensures that the first and last character in the field are alphabets, and allows anything else in-between. My conc...

Challenge: How to turn an NSArray of numbers into an English-readable list

Hi all, I'm looking for a nice clean routine for turning an NSArray containing NSNumbers (integers) into a nice English-readable string. For example, I want to change this: [NSArray arrayWithObjects:[NSNumber numberWithInt:5], [NSNumber numberWithInt:7], [NSNumber numberWithInt:12], ...

Python compile all non-words except dot[.]

I am trying to break a line on all non-word patterns except .(dot) Usually I guess it can be done as [\W ^[.]] in java, but how to I do in python? ...

RegexKitLite not matching square brackets

I'm trying to match usernames from a file. It's kind of like this: username=asd123 password123 and so on. I'm using the regular expression: username=(.*) password To get the username. But it doesn't match if the username would be say and[ers] or similar. It won't match the brackets. Any solution for this? ...

Regex to calculate straight poker hand?

Is there a regex to calculate straight poker hand? I'm using strings to represent the sorted cards, like: AAAAK#sssss = 4 aces and a king, all of spades. A2345#ddddd = straight flush, all of diamonds. In Java, I'm using these regexes: regexPair = Pattern.compile(".*(\\w)\\1.*#.*"); regexTwoPair = Pattern.compile(".*(\\w)\\1.*(\\w)\\...

REGEX: Make all URLs absolute

I need a way to take a block of HTML code and make all URLs absolute. I've tried to adopt various regex examples out there but had no luck. These are the requirements: Replace both HREF and SRC urls If URL is already absolute, leave it If URL is absolute, replace it Each HTML comes from a known URL (example.com/folder/file.html) whic...

PHP Help with regular expressions... error: Delimiter must not be alphanumeric.

I am new to regexp in php. I am just trying to do a simple preg_match on two strings. Here is my code: $pattern = '\\w*'.strtolower($CK); if(preg_match($pattern, $rowName, $matches) == true) { echo 'true'; } But I keep getting the error: Warning: preg_match() [function.preg-match]: Delimiter ...

Perl regex replacing at word boundary. Detecting "/" as a word boundary

Hi everyone, I am running into a strange regex issue.... I have a document where I am doing a replace... as an example I want to replace "DEXX" with "DEXX/AREX" and then with the next substitution replace... "AREX" with "AREX/CUBE" DEXX and AREX are stored in a hash like so.... "DEXX" => "AREX", "AREX" => "CUBE" The regex I have is thi...

Replace string with regular expression

I have the below situation Case 1: Input : X(P)~AK,X(MV)~AK Replace with: AP Output: X(P)~AP,X(MV)~AP Case 2: Input: X(PH)~B$,X(PL)~B$,X(MV)~AP Replace with: USD$ Output: X(PH)~USD$,X(PL)~USD$,X(MV)~USD$ As can be make out that, always the ~<string> will be replaced. Is it possible to achieve the same through regular expressi...