regex

is there need for a more declarative way of expressing regular expressions ? :)

Hi, I am trying to create a Python function that can take an plain English description of a regular expression and return the regular expression to the caller. Currently I am thinking of the description in YAML format. So, we can store the description as a raw string variable, which is passed on to this another function and output of th...

regex question - replace all newlines that are not preceded by a tab with a space

I have to process a block of text, which might have some spurious newlines in the middle of some of the fields. I want to strip these newlines out (replacing them with spaces), without stripping out the 'valid' newlines, which are always preceded by a \t. So, i want to replace all newlines that are not preceded by a tab with a space. ...

Javascript/Regex for finding just the root domain name without sub domains

I had a search and found lot's of similar regex examples, but not quite what I need. I want to be able to pass in the following urls and return the results: www.google.com returns google.com sub.domains.are.cool.google.com returns google.com doesntmatterhowlongasubdomainis.idont.wantit.google.com returns google.com sub.domain.google.c...

Perl: Use s/ (replace) and return new string

In Perl, the operator s/ is used to replace parts of a string. Now s/ will alter its parameter (the string) in place. I would however like to replace parts of a string befor printing it, as in print "bla: ", replace("a","b",$myvar),"\n"; Is there such replace function in Perl, or some other way to do it? s/ will not work directly in t...

Need a regex that matches URLs with/without http:// or www. or http://www. in a text

I've been trying to find a solution myself but I couldnt do it so far (even tried all regexlib.com suggestions), so: Need a regex that matches URLs like (PHP code): http://example.com orhttp://www.example.com or www.example.com example.com ...

Match a Comma that isn't within quotes

Hello all, I am trying to write a regex that will allow me to parse CSV files that excel creates. I have noticed when you export a CSV from excel, if the field is a string it will encase it in quotes. If that string contains quotes itself, it will escape each quote with a quote!! What I want to do is split each line that I parse into f...

Temporary redirect 302 with .htaccess and mod-rewrite matching expression

Hi! I'm trying to match a a bunch of redirects for my website with basically moved to a different folder on the server. I need to make http://www.site.com/index.php?page=anypage go to http://www.site.com/newfolder/index.php?page=anypage. The thing is http://www.site.com/index.php and http://www.site.com/index.php?page=home should remain ...

Regular expressions to remove space and whitespace in PHP?

I'm looking for regular expressions to remove space and whitespace before and after a comma. ...

Multiple regular expression interfere

I use regex to create html tags in plain text. like this loop $SearchArray[] = "/\b(".preg_quote($user['name'], "/").")\b/i"; $ReplaceArray[] = '<a href="'.$user['url'].'">$1</a>'; - $str = preg_replace($SearchArray, $ReplaceArray, $str); I'm looking for a way to not match $user['name'] in a tag. ...

PHP REGEX: Get domain from URL

What I want I want to get from a URL the domain part so from http://example.com/ -> example.com Examples: +----------------------------------------------+-----------------------+ | input | output | +----------------------------------------------+-----------------------+ | http:...

Perl regex syntax generation

This is a follow up to the question posted here: http://stackoverflow.com/questions/3358361/perl-regex-syntax The results from that discussion yielded this script: #!/usr/bin/env perl use strict; use warnings; my @lines = <DATA>; my $current_label = ''; my @ordered_labels; my %data; for my $line (@lines) { if ( $line =~ /^\/(.*)$...

preg_replace not replacing in a Wordpress plugin

In follow-up to my previous question, I want to replace every instance of an ALL-CAPS* word with a link of the following format: dictionary.com/browse/<TERM> The preg_replace call I am using is this: $content = preg_replace('#[A-Z][A-Z]+#', '<a href="//dictionary.com/browse/$1">$1</a>', $content); Using http://gskinner.com/RegExr, ...

Javascript regular expression global replace on strings with variables

I'm trying to add soft hyphens to break up long urls and other strings in some plain text. function breakLines(str, num){ if(typeof num == 'undefined' || num == null){ num = 15;} regex = new RegExp('(\S{'+num+'})(\S{'+num+'})','g'); return str.replace(regex, '$1&shy;$2'); } It works if I use the slash notation for the repl...

Matching parts of string that contain no consecutive dashes

I need a regex that will match strings of letters that do not contain two consecutive dashes. I came close with this regex that uses lookaround (I see no alternative): ([-a-z](?<!--))+ Which given the following as input: qsdsdqf--sqdfqsdfazer--azerzaer-azerzear Produces three matches: qsdsdqf- sqdfqsdfazer- azerzaer-aze...

How do I match a number inside square brackets with regex

I wrote a regular expression which I expect should work but it doesn't. var regex = new RegExp('(?<=\[)[0-9]+(?=\])') Javascript is giving me the error Invalid regular expression :(/(?<=[)[0-9]+(?=])/): Invalid group Does javascript not support lookahead or lookbehind? ...

Can a regex be used as input method?

Hi, I saw somewhere that a regex can be used as an input method, is this possible? How? I really don't know anything else about that, I supposed that there's a way to procude Strings from a regex and feed an object with that String, again, this is only what I pictured and I don't know if it's even possible. EDIT I know I didn't explain...

Need help with the Matcher

Hello, I have following regex (abc|def)( ?(\\d+|(?:(?!\\1)[a-z])+)?)* with matches perfectly the subject abc123 456. Now I want to get all parts abc, 123 and 456. I use following code: Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(subject); while(m.find()) { System.out.println(m.group()); } ...

RegEx in Java: Problem with newline

I am currently trying to learn how to use regular expressions so pelase bear with my simple question. For example, say I have an input file containing a bunch of links separated by a newline: www.foo.com/Archives/monkeys.htm Description of Monkey's website. www.foo.com/Archives/pigs.txt Description of Pig's website. www...

Escape string for use in Javascript regex

I am trying to build a javascript regex based on user input: function FindString(input) { var reg = new RegExp('' + input + ''); // [snip] perform search } But the regex will not work correctly when the user input contains a ? or * because they are interpreted as regex specials. In fact, if the user puts an unbalanced ( or [ ...

parse string with regex

Hello everyone, I am trying to search a string for email addresses, but my regex does not work, when the string contains other characters than the email. Meaning, if I try on a small string like "[email protected]", the regex finds a match. If I insert a blank space in the string, like: " [email protected]", the regex does not find an email match...