regex

Seeking quoted string generator

Does anyone know of a free website or program which will take a string and render it quoted with the appropriate escape characters? Let's say, for instance, that I want to quote It's often said that "devs don't know how to quote nested "quoted strings"". And I would like to specify whether that gets enclosed in single or double quo...

How do I extract words and phrases from a string using an array in Javascript (JS) ?

I looked at several examples on how to use regex in JS but I can not seem to find the right syntax for what I need. Basically I have an array of words: commonWords=["she", "he", "him", "liked", "i", "a", "an", "are"] and a string: 'She met him where he liked to eat "the best" cheese pizza.' Basically I want to use non-alphas and my...

Whats the difference between sed -E and sed -e

I'm working on some old code and I found that I used to use sed -E 's/findText/replaceWith/g' #findText would contain a regex but I now try sed -e 's/findText/replaceWith/g' It seems to do the same thing, or does it? I kinda remember there being a reason I done it but I can't remember and doing "man sed" doesn't help as they don'...

find-and-replace-in-html regular expression fails

I have a regular expression that looks through html content for some keywords that used to work, but now fails and i don't understand why. (The regular expression came from this thread.) $find = '/(?![^<]+>)(?<!\w)(' . preg_quote($t['label']) . ')\b/s'; $text = preg_replace_callback($find, 'replaceCallback', $text); function replaceCal...

how to remove leading and trailing non-alphabetic characters in ruby

I want to remove any leading and trailing non-alphabetic character in my string. for eg. ":----- pt-br:-" , i want "pt-br" Thanks ...

regular expression that extracts words from a string

I want to extract all words from a java String. word can be written in any european language, and does not contain spaces, only alpha symbols. it can contain hyphens though. ...

Pass a variable into regex with string replace.

I have a complicated regEx inside a string replace and I want to use a variable called "tagname" instead of the word Category, but I don't know how to do this. $("textarea").val().replace(/\<Category\>(.*)\<\/Category\>/gi, "<Category>TextVariable</Category>"); I have tried something like this, but it didn't work in the first paramet...

C# Regex to match enum body type

I have this enum defitiion in file: public enum IdentityState { [EnumMember] New = 0, [EnumMember] Normal = 1, [EnumMember] Disabled = 2 } { some other data... } And want to match only body of this enum (between {}), the match result i want is: { [EnumMember] New = 0, [EnumMember] Normal = 1, ...

Multiple substitutions with a single regular expression in perl

Say I have the following in perl: my $string; $string =~ s/ /\\ /g; $string =~ s/'/\\'/g; $string =~ s/`/\\`/g; Can the above substitutions be performed with a single combined regular expression instead of 3 separate ones? ...

unicode preg_replace problem in php

I've got the string $result = "bei einer Temperatur, die etwa 20 bis 60°C unterhalb des Schmelzpunktes der kristallinen Modifikation" which comes straight from a MySQL table. The table, and the php headers are both set to UTF-8 I want to strip the 'degree' symbol: http://en.wikipedia.org/wiki/Degree_symbol and replace it with the wor...

Python regex \w doesn't match combining diacritics?

I have a UTF8 string with combining diacritics. I want to match it with the \w regex sequence. It matches characters that have accents, but not if there is a latin character with combining diacritics. >>> re.match("a\w\w\wz", u"aoooz", re.UNICODE) <_sre.SRE_Match object at 0xb7788f38> >>> print u"ao\u00F3oz" aoóoz >>> re.match("a\w\w\wz...

Regular expression problems

I can't get the preg_match to find a word anywhere a the string. I have this: $bad_words = "/(\bsuck\b)|(\bsucks\b)|(\bporn\b)|"; $text = "sucky"; if(preg_match($bad_term_filter, trim($feedback_review_comment)) != 0 ) I need to return true but it only returns true if its an exact match, for example if $text = "suck"; that return...

Increment a Version Number using Regular Expression

Hello, I am trying to increment a version number using regex but I can't seem to get the hang of regex at all. I'm having trouple with the symbols in the string I am trying to read and change. The code I have so far is: version_file = "AssemblyInfo.cs" read_file = open(version_file).readlines() write_file = open(version_file, "w") ...

How to capture multiple regex matches, from a single line, into the $matches magic variable in Powershell?

Let's say I have the string "blah blah F12 blah blah F32 blah blah blah" and I want to match the F12 and F32, how would I go about capturing both to the Powershell magic variable $matches? If I run the following code in Powershell: $string = "blah blah F12 blah blah F32 blah blah blah" $string -match "F\d\d" The $matches variable onl...

Java regex: Get the matched sequence

In Perl/PHP regex is's possible to match a sequence and get an array with matched sequences: preg_match('/20[0-1][0-9]/', $inputstring, $array_return); // PHP I can't figure out how to do this in Java. match.group() returns the whole string. Is this impossible? ...

Lookahead assertions seem to short-circuit ordering of alternates in regular expressions

I'm working with a (Python-flavored) regular expression to recognize common and idiosyncratic forms and abbreviations of scripture references. Given the following verbose snippet: >>> cp = re.compile(ur""" (?:( # Numbered books (?:(?:Third|Thir|Thi|III|3rd|Th|3)\ ? (?:John|Joh|Jhn|Jo|Jn|Jn|J)) # O...

Parse text and convert links

Does anybody know of a good library out there for taking a string of text and using regex (or whatever you want) to parse out any urls to links? For example: Input: I found this great site called google.com. You can e-mail the webmaster at [email protected]. Output: I found this great site called <a href="http://google.com&quot;&gt;...

RegEx pattern not showing matches

I have the following code: public void DriveRecursion(string retPath) { string pattern = @"[~#&!%\+\{\}]+"; Regex regEx = new Regex(pattern); string[] fileDrive = Directory.GetFiles(retPath, "*.*", SearchOption.AllDirectories); List<string> filePath = new List<string>(); List<string> filePat...

Help Parsing a string in PHP

I will have a string like this: Bob is a boy. Bob is 1000 years old! <b>Bob loves you!</b> Do you love bob? I want to parse it into an array, using the following delimiters to identify each array element: . ! ? <b> and </b> So I will have an array with the following structure: [0]Bob is a boy. [1]Bob is 1000 years old! [2]Bob love...

javascript regex iso datetime

does anyone have a good regex pattern for matching iso datetimes? ie: 2010-06-15T00:00:00 ...