regex

Reg exp to Null/empty string if string contains non alphanumeric characters

Hey Guys, I'm looking for a php preg replace to null/empty string if string contains any non alphanumeric characters or spaces e.g. Strings $string = "This string is ok"; $string = "Thi$ string is NOT ok, and should be emptied" When I say emptied/nulled I mean it will make the string "". So basically anything a-z A-Z 0-9 or space ...

jQuery Regular Expressions - Strip ID from URL

I am being fed a url that looks like this: http://hamilton.kijiji.ca/c-buy-and-sell-sports-bikes-Kids-bike-W0QQAdIdZ215282410 I want to pull out the numbers after adIdZ How can I pull these numbers off dynamically? ...

Python: finding files with matching extensions or extensions with matching names in a list.

Suppose I have a list of filenames: [exia.gundam, dynames.gundam, kyrios.gundam, virtue.gundam], or [exia.frame, exia.head, exia.swords, exia.legs, exia.arms, exia.pilot, exia.gn_drive, lockon_stratos.data, tieria_erde.data, ribbons_almark.data, otherstuff.dada]. In one iteration, I'd like to have all the *.gundam or *.data files, where...

Using array_key_exists with preg_match

Hi, I'm trying to determine if a match, or matches exist within an array based on a pattern, an example of the array: Array ( [author_id] => 1 [channel_id] => 1 [site_id] => 1 [entry_id] => 6 [url_title] => test_title_with_file2 [title] => Test Title with file [field_id_1_directory] => 1 [field_id_4_dir...

sed + replace word on directory PATH

Hi all How to replace the <x> with word Before_last_dir only on the dir that located before the last dir (according to this example – dir4) echo "/dir1/dir2/dir3<x>/dir4<x>/dir5<x>" |sed s"/<x>/Before_last_dir/g" Another example echo "/dirA<x>/dirB<x>/dirC<x> >" |sed s"/<x>/Before_last_dir/g" should be /dirA<x>/dirBBefore_l...

I don't understand a regexp

I'm following along a tutorial (Ruby) that uses a regex to remove all html tags from a string: product.description.gsub(/<.*?>/,''). I don't know how to interpret the ?. Does it mean: "at least one of the previous"? In that case, wouldn't /<.+>/ have been more adequate? ...

PHP REGEX: Ignore + and #

So here is what I'm doing exactly: I have a form with a caption on the right of it, I want to write in the form only A-Z,0-9 and whitespaces, and for the caption I want to do the opposite, so if the user write's something wrong I can show what's the problem for example: "Invalid Charachter" But I'm stuck with + and # I want to ignore ...

How to extract parameters names from SQL statement using regular expression

Hi, I want to extract the parameters names from a query like this: select * from table where a = :param1 and b = :param2 I wrote this expression:"(?<param>:\w* )" It gives me :param1 twice Note: It's in a C#.Net application. Any Help !! Thanks ...

PHP replace text in variable

$image variable gives this code (when echo is used): <img src="/image.png" width="100" height="147" alt="" class="some_class" /> width, height, src and class attributes can be different. What should we do: remove width and height from $image replace alt="" with alt="Poster" Thanks. ...

What am I doing wrong with my regex?

Hello, I am trying to capture "Rio Grande Do Leste" from: ... <h1>Rio Grande Do Leste<br /> ... using var myregexp = /<h1>()<br/; var nomeAldeiaDoAtaque = myregexp.exec(document); what am I doing wrong? update: 2 questions remain: 1) searching (document) didn´t produce any result, but changing it to (document.body.innerHTML) w...

What's up with this regular expression not matching?

public class PatternTest { public static void main(String[] args) { System.out.println("117_117_0009v0_172_5738_5740".matches("^([0-9_]+v._.)")); } } This program prints "false". What?! I am expecting to match the prefix of the string: "117_117_0009v0_1" I know this stuff, really I do... but for the life of me, I've been star...

RegEx, colon separated list.

I am trying to match a list of colon separated emails. For the sake of keeping things simple, I am going to leave the email expression out of the mix and match it with any number of characters with no spaces in between them. The following will be matched... somevalues ;somevalues; somevalues; or somevalues; somevalues ...

Regex to get page number from the url

I am currently using this regex to get the page number from the url: @"\/(\d+)$"; Which worked fine for urls like: /some_category/2 /some_category2/323 My urls now have some additional querystring values (optionally), so the current regex is not working for these cases. So now I need a regex to support: /some_category/2 ...

Remove links from text file

Hi, how can I remove links from a raw html text? I've got: Foo bar <a href="http://www.foo.com"&gt;blah&lt;/a&gt; bar foo and want to get: Foo bar blah bar foo afterwards. ...

What's wrong with my regular expression?

I'm expecting a string NOT to match a regular expression, but it is! >>> re.compile('^P|([LA]E?)$').match('PE').group() 'P' This seems like a bug, because I see no way for the $ to match. On the other hand, it seems unlikely that Python's re lib would not be able to handle this simple case. Am I missing something here? btw, Python pr...

Unicode Regular Expressions - Fails at 343 characters

Hi, I am using the regular expression below to weed out any non-Latin characters. As a result, I found that if I use a string larger than 342 characters, the function fails, everything aborts, and the website connection is reset. I narroed it down to the \p{P} unicode character property, which matches any punctuation character. Does ...

R: replacing double escaped text

I'm gluing together a number of system calls using the Amazon Elastic Map Reduce command line tools. These commands return JSON text which has already been (partially?) escaped. Then when the system call turns it into an R text object (intern=T) it appears to get escaped again. I need to clean this up so it will parse with the rjson pack...

Regular Expression for tags

I need to write regular expression that will match any pair of tags <(.*?)>.*?</\1> but only if there is no other pair tags between them. Tag names are variable length. ...

RegEx (in JavaScript find/replace) - match non-alphanumeric characters but ignore - and +

We have been using the following js/regex to find and replace all non-alphanumeric characters apart from - and + outputString = outputString.replace(/[^\w|^\+|^-]*/g, ""); However it doesn't work entirely - it doesn't replace the ^ and | characters. I can't help but wonder if this is something to do with the ^ and | being used as meta-...

How to traverse through the long string and replace certain block with certain text?

I need to replace <slot> slot_name </slot> with a <?php !include_slot('slot_name')?> in the text that I read from file <table class="layout-table" id="layout1"> <tr> <td class="slot" id="slot1" colspan="2"> <slot> slot_name </slot> </td> </tr> <tr> <td class="sl...