regex

I'm trying to match some numbers in a string using a regexpressions and am having difficulty with the syntax

here is the line i'm trying to parse [\\?\Volume{d3f7f470-526b-11df-92eb-001a647802d2}\] 85 90 NotFound I'm basically just trying to get the numbers that are outside of the brackets and ignore anything in between the brackets. My original syntax worked until I realized that sometimes there would be numbers in the brackets (I was just...

preg_replace, exact opposite of a preg_match

I need to do a preg_replace for the exact opposite of this preg_match regular expression: preg_match('#^(\w+/){0,2}\w+\.\w+$#', $string); So I need to replace all strings that are not valid with an empty string -> '' So it needs to remove the first / and last / if found, and all non-valid characters, that is the only valid characters...

Regex optional match in python fails

tickettypepat = (r'MIS Notes:.*(//p//)?.*') retype = re.search(tickettypepat,line) if retype: print retype.group(0) print retype.group(1) Given the input. MIS Notes: //p// Can anyone tell me why group(0) is MIS Notes: //p// and group(1) is returning as None? I was originally using regex because, before I ran into problems ...

preg_match problem.

How do I add the character - within the preg_match? preg_match('#^(\w+/){0,2}\w+\.\w+$#', $string) But it must be before the last . within the string. I've tried just about everything I know here. I know that the - needs to be escaped. So I tried to escape it in various places, but it's not working :( argggg ...

Ruby equivalent to "grep -C 5" to get context of lines around the match?

I've searched for this a bit but I must be using the wrong terms - does ruby have a way to grep for a string/regex and also return the surrounding 5 lines (above and below)? I know I could just call "grep -C 5 ..."or even write my own method, but it seems like something ruby would have and I'm just not using the right search terms. ...

Regex with dynamic <textarea>

How can I do this with the JS replace() method: Make \n\n change to <p>$1</p> Change single \n to <br> Then back again. I think I have this part, see the JS at the bottom. Example HTML: <p>Hello</p><p>Wor<br>ld</p> The <textarea> would look like: Hello Wor ld So, how can I achieve this? It's an AJAX form where when you click o...

How to add http:// if it's not exists in the URL?

Hi, How to add http:// to the url if there isn't a http:// or https:// or ftp:// ? Example: addhttp("google.com"); // http://google.com addhttp("www.google.com"); // http://www.google.com addhttp("google.com"); // http://google.com addhttp("ftp://google.com"); // ftp://google.com addhttp("https://google.com"); // https://google.com ad...

Detecting a url using preg_match? without http:// in the string

Hey there, I was wondering how I could check a string broken into an array against a preg_match to see if it started with www. I already have one that check for http://www. function isValidURL($url) { return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); } $stringToArray = explode(" ",$_POST['text']); ...

Splitting a filename into words and numbers in Python

The following code splits a string into a list of words but does not include numbers: txt="there_once was,a-monkey.called phillip?09.txt" sep=re.compile(r"[\s\.,-_\?]+") sep.split(txt) ['there', 'once', 'was', 'a', 'monkey', 'called', 'phillip', 'txt'] This code gives me words and numbers but still includes "_" as a valid...

Python RegExp exception

How do I split on all nonalphanumeric characters, EXCEPT the apostrophe? re.split('\W+',text) works, but will also split on apostrophes. How do I add an exception to this rule? Thanks! ...

regular expression for email validation

i am using the follwoing regular expression (".+@.+\\.[a-z]+") Bit it accepts #@#.com as a valid email.whats the pattere i shold use? ...

How to replace only part of the match with python re.sub

I need to match two cases by one reg expression and do replacement 'long.file.name.jpg' -> 'long.file.name_suff.jpg' 'long.file.name_a.jpg' -> 'long.file.name_suff.jpg' I'm trying to do the following re.sub('(\_a)?\.[^\.]*$' , '_suff.',"long.file.name.jpg") But this is cut the extension '.jpg' and I'm getting long.file.name_suff. ...

Perl Substitution

hi, I have a variable which stores the path on Windows. I want to replace all the \ with / in the path. for eg. $path = C:\Users\scripts.ps1 Am new to Perl and tried something like $path = s/\\//// But it didnt work. can you please help me out.... ...

Regex for Username?

Hi Guys, I am using C# and jQuery to valid a username with Regex. Just learning :) So far I have UserName = "[a-zA-Z0-9]"; But this doesn't stop symbols ? How to ensure that no symbols or " . " or " _ " ? Thanks ...

Regex.Replace() for replacing the whole occurrence

Hi, Am using regex.Replace() to replace the whole occurrence of a string.. so I gave like Regex.Replace(str,@stringToReplace,"**"); where stringToReplace = @"session" + "\b"; if i give like that its not replacing.. but if i give like Regex.Replace(str,@"session\b","**"); then its working.. how to avoid this.. i want to pass value whic...

c# and regEx to pull href part of links on html pages

i have this code in c# to pull links from a web page and wanted to make it smarter in that i want to be able to add small additions in the fuure to exclude links based on 2 criteria. first i want to exclude certain file extentions found on pages such as links to pdf files or ppt files... next i want to be able to exclude links on the f...

Find telephonenumbers - finding number with and without an phone extension

Hello there I've a table with about 130 000 records with telephonenumbers. The numbers are all formated like this +4311234567. The numbers always include international country code, local area code and then the phonenumber and sometimes an extension. There is a webservice which checks for the caller's number in the table. That servic...

combining dynamic text with regular expressions in php

I am experimenting with finding popular keywords using curl, php and regular expressions. I have an array of non-specific nouns that I am matching my keyword search up. So I am looking for words like "the", "and", "that" etc. and taking them out of the keyword search. so I have an array of words like so: $wordArr = [the, and, at,.......

extract every occurrence on string

I have a string of the form "a-b""c-d""e-f"... Using preg_match, how could I extract them and get an array as: Array ( [0] =>a-b [1] =>c-d [2] =>e-f ... [n-times] =>xx-zz ) Thanks ...

Extract string from string using Regex

I want to extract MasterPage value directive from a view page. I want the fastest way to do that, taking into account a very big aspx pages, and a very small ones. I think the best way is to do that with two stages: Extract the page directive section from the view (using Regex): <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Si...