regex

PHP - How to split a paragraph into sentences.

I've been trying to use $string="The Dr. is here!!! I am glad I'm in the U.S.A. for the Dr. quality is great!!!!!!"; preg_match_all('~.*?[?.!]~s',$string,$sentences); print_r($sentences); but it doesn't work on Dr. , U.S.A., etc.. Does anyone have any better suggestions? ...

RegEx for a string to NOT contain two different strings

Ok you gurus out there who know Regex! How do you use reg ex to search a string to make sure it doesn't contain either of two different strings. Example: Say i want to make sure "FileNTile" doesnt contain File or Tile Thanks cnorr ...

Regex : how to get words from a string (C#)

My input consists of user-posted strings. What I want to do is create a dictionary with words, and how often they've been used. This means I want to parse a string, remove all garbage, and get a list of words as output. For example, say the input is : "#@!@LOLOLOL YOU'VE BEEN *PWN3D* ! :') !!!1einszwei drei !" The output I need is the...

How can I safely use regexes from user input?

My (Perl-based) application needs to let users input regular expressions, to match various strings behind the scenes. My plan so far has been to take the string and wrap it in something like $regex = eval { qr/$text/ }; if (my $error = $@) { # mangle $error to extract user-facing message ($text having been stripped of newlines ahe...

Regex of non breaking space in php

input: $string = "a b c d e"; i have a string in php and I need to replace the string with the non-break space code output: "a \xc2\xa0b c \xc2\xa0d \xc2\xa0\xc2\xa0e" single space and the first space is not allowed to replace with \xc2\xa0 when two space appear " ", the output is " \xc2\xa0", first space is kept and the se...

Regex for getting javascript functions in C#.net

I use webBrowser.DocumentText to get the html code of a page. using Regex, i manage to get the script tag part. < script type="text/javascript">functions here..< /script> I need to get functions inside those tags. ex. <script type="text/javascript"> function function1 () { code here;} function function2 () { code here;} <br> </scri...

Regular expression with an empty group "()" returning strange results

It is a bit pushing the edge, but I have the following situation with this regular expression - "()" : When used to split a string into a string[] array, the results are somewhat weird to me. For example this line of code : string[] res = new Regex("()").Split("hi!"); sets res to an array of 9 (!) elements : ["","","h","","i","","!","...

e-modifier in javascript? (converting regex from php to js)

Hi, I have the following regular expression in PHP $url = 'http://www.amazon.com/dp/B002JCSBE4/ref=sr_1_1?ie=UTF8&s=tv&qid=1264738369&sr=1-1/'; $url=preg_replace( '/http:\/\/[^>]*?amazon.(.*)\/([^>]*?ASIN|gp\/product|exec\/obidos\/tg\/detail\/-|[^>]*?dp)\/([0-9a-zA-Z]{10})[a-zA-Z0-9#\/\*\-\?\]*/i', 'http://www.amazon.$1/dp/$3/?tag='.'...

compare portion of the string using php

Hi, I want to check whether the search keyword 'cli' or 'ent' or 'cl' word exists in the string 'client' and case insensitive. I used the preg_match function with the pattern '\bclient\b'. but it is not showing the correct result. Match not found error getting. Please anyone help Thanks ...

Replacing a string with certain elements in an array (PHP)

I have a paragraph of text like: $paragraph = "Hello there {Customer.name}, You are {Customer.age} years old. You were born in the year {Customer.birthdate}"; I want to replace this with contents of an array such as array('Customer' => array('name'=>'Tom', 'age'=>8, 'birthdate'=>'1980-01-01')) My question is what is the best way to...

match url that doesnt contain asp, apsx, css, htm.html,jpg

Q-1. match url that doesn't contain asp, apsx, css, htm.html,jpg, Q-2. match url that doesn't end with asp, apsx, css, htm.html,jpg, ...

Parsing SGML and storing it in a PHP array

If you can help with this you're a genius. Basically, I will have some text like this: <parent wealthy> <parent> <children female> <child> jessica <hobbies> basketball, soccer, video games </hobbies> </child> <child> jane <hobbies> ...

String parsing help

I have a paragraph of text in the following format: text text text <age>23</age>. text text <hobbies>...</hobbies> I want to be able to 1) Extract the text found between each <age> and <hobbies> tag found in the string. So for example, I would have an array called $ages which will contain all ages found between all the <age></age> ...

Quick regexp to get path

I need to extract the full path to a file using regExp mydomain.com/path/to/file/myfile.html -> mydomain.com/path/to/file/ /mypath/file.txt -> /mypath/ anyone? ...

Regex to seperate Numeric from Alpha

I have a bunch of strings: "10people" "5cars" .. How would I split this to? ['10','people'] ['5','cars'] It can be any amount of numbers and text. I'm thinking about writing some sort of regex - however I'm sure there's an easy way to do it in Python. ...

Regular Expression - replace word except within a URL/URI

Writing a globalization module for a web application and I need a regexp to replace all instances of a word with another word (the translation) - except - words found within a URL/URI. EDIT: I forgot to mention that I'm using Ruby, so I can't use 'Lookbehind' ...

Regex not working in .NET

So I'm trying to match up a regex and I'm fairly new at this. I used a validator and it works when I paste the code but not when it's placed in the codebehind of a .NET2.0 C# page. The offending code is supposed to be able to split on a single semi-colon but not on a double semi-colon. However, when I used the string "entry;entry2;entr...

Using Path.GetDirectoryName on command string with optional parameters and quotes

Our clients have a string stored in their registry which is an executable command. The string may or may not have quotes around the target path, and may or may not have parameters. For example: "C:\path\file.exe" param1=value1 param2=value2 C:\path\file.exe param1=value1 param2=value2 "C:\path\file.exe" C:\path\file.exe "C:\p...

Regular expression for finding non-breaking string names in code and then breaking them up for SQL query

I am trying to devlop a regex for finding camel case strings in several code files I am working with so I can break them up into separate words for use in a SQL query. I have strings of the form... EmailAddress FirstName MyNameIs And I want them like this... Email Address First Name My Name Is An example SQL query which I currentl...

Ruby split with regex - regex isn't doing what i want...

i have this string string = "<p>para1</p><p>para2</p><p>para3</p>" I want to split on the para2 text, so that i get this ["<p>para1</p>", "<p>para3</p>"] The catch is that sometimes para2 might not be wrapped in p tags (and there might be optional spaces outside the p and inside it). I thought that this would do it: string.split(...