regex

Using javascript regexp to find the first AND longest match

I have a RegExp like the following simplified example: var exp = /he|hell/; When I run it on a string it will give me the first match, fx: var str = "hello world"; var match = exp.exec(str); // match contains ["he"]; I want the first and longest possible match, and by that i mean sorted by index, then length. Since the expression ...

caret/negate for a word in regular expression

[^a-zA-Z] - matches anything except a,b,c,...z , A, B, ..Z I want expression that matches anything except (abc) AND except (xyz) I want a regex for image tag I tried img.*src - it matches the initial part but between img and src there should not be any other image tag so I put a caret img[^(neither <img nor src=)] how to use ^ with a...

Regex - Matching Abbreviations of a Word

I was thinking in providing the following regex as an answer to this question, but I can't seem to write the regular expression I was looking for: w?o?r?d?p?r?e?s?s? This should match a ordered abbreviation of the word wordpress, but it can also match nothing at all. How can I modify the above regex in order for it to match at least ...

C# Find if a word is in a document

Hi, I am looking for a way to check if the "foo" word is present in a text file using C#. I may use a regular expression but I'm not sure that is going to work if the word is splitted in two lines. I got the same issue with a streamreader that enumerates over the lines. Any comments ? ...

Getting contents of square brackets, avoiding nested brackets

(first time poster, long time visitor via Google) I'm trying to extract the contents of some square brackets, however i'm having a spot of bother. I've got it working for round brackets as seen below, but I can't see how it should be modified to work for square brackets. I would have thought replacing the round for square and vice versa...

How to pull the filenames from an .htm file using PowerShell's select-string?

I am trying to search through the .htm files for our intranet to find out which network files are being linked to on which pages of the site. What I would like to do is have PowerShell go through each .htm and return any string that begins with "file:///" and ends with a double quote. For instance: <td colspan="3"><a href="file:///X:/...

PHP String Parsing

Hi! I have string which contains something about "amount 3 val 6, amount 7 val 8" and so, what regular expression should I use to get array with corresponding amounts and values? ...

C# formatting regex problem

What I have is a config file with 100's of lines that has the following format: Input line : FHF02030304|C:\sd\dad\qwe\re|{203-207}.TXT|5` The format is : ID|Directory|Text|# txts The formula for the additional lines is Text (in example 203) +1 -1. so in the following example 203 +1 -1 = 203 (the first file) 203+2-1 = 204 (the 2nd ...

RegexValidator for name and surname

Hello, How should like a regex which validates the name and surname, so that each word starts with a capital letter? this does not work: @"[^A-Z]?[a-z]*" Thanks ...

jQuery/JS, removing/trimming trailing html line breaks?

I'm looking for some ideas for the most efficient way to remove trailing html <br/> tags using javascript or jquery. RULES: The br, at the front and end must be removed. It must remove non-closing and self-closing br tags. All br within the textual content must remain untouched. THE HTML: <div class="generatedContent...

Not Another Parse-HTML-With-Regex Question

Hello, I've read a few questions on here re parsing HTML with regex, and I understand that this is, on the whole, a terrible idea. Having said this, I have a very specific problem that I think Regex might be the answer to. I've been fumbling around trying to work out the answer but I'm new (today) to Regex, and I was hoping some kind ...

Regular Expression to ensure between 7 and 16 characters with at least 1 numeric character?

I am using the LiveValidation library found at www.livevalidation.com to handle client-side validation. One of the functions is to test for a regular expression. The example they provide on the site is to check if the phrase 'live' is within the a sentence. The code for that is: var f2 = new LiveValidation('f2'); f2.add( Validate.For...

Match the first number/word/string in quotation marks in the Input - Regex Help

Hi, I want to match the first number/word/string in quotation marks/list in the input with Regex. For example, it should match those: "hello world" gdfigjfoj sogjds -14.5 fdhdfdfi dfjgdlf test14 hfghdf hjgfjd (a (c b 7)) (3 4) "hi" Any ideas to a regex or how can I start? Thank you. ...

C# Regex replace help.

I have a string: Apple1231|C:\asfae\drqw\qwer|2342|1.txt I have the following code: Regex line2parse = Regex.Match(line,@"(\|)(\|)(\|)(\d)"); if (line2parse < 2) { File.AppendAllText(workingdirform2 + "configuration.txt", What I want to be able to do is replace every | after the first | with \ So i want to write out ...

Assistance with APACHE www.conf file correctly matching location?

I have one location match that correctly works: <LocationMatch "^/user/storage/subaccounts(/[a-zA-Z0-9]+)?/?$"> this correctly forwards for something like /user/storage/subaccounts/exampleuser or /user/storage/subaccounts/ I'd like to setup a locationmatch for /user/storage/subaccounts/exampleuser/admin My attempt at this was: <Loc...

Does python have the equivalent of Perl's regex "local" variable?

While searching for a solution to a python regular expression problem I found this page which demonstrates that [some version of] perl allows variables within regular expressions. e.g. a perl regex something like: ^(?{ local $d=0}\((?{ $d++ }.*?\)(?d--) Where variable $d is incremented and decremented depending on which part of the ...

What regular expression will match valid international phone numbers?

I need to determine whether a phone number is valid before attempting to dial it. The phone call can go anywhere in the world. What regular expression will match valid international phone numbers? ...

Regex for optional leading forward slashes

Hi all, I need to validate shipping container numbers. There is an industry standard that says only alpha-numeric and 11 characters in length is acceptable. eg: FBXU8891735 However there is also a standard industry practice where the first 4 characters can be forward-slashes eg: ////8891735 I have 2 requirements - firstly to validate ...

Replace last instance of a character in a string using regex

I have a csv file with the data like this Zoos, Sanctuaries & Animal Parks,7469,3.00 Unfortunately this is not correct as the first section should be all one field like this "Zoos, Sanctuaries & Animal Parks","7469","3.00" As this is just a once off import I would be just happy to transform it to Zoos, Sanctuaries & Animal Parks|7...

How can I unescape backslashes in a Perl string?

I need the to convert the input address to specified format #!/usr/bin/perl my $file_path ="\\\abc.com\a\t\temp\L\\"; #---- Help in this regex $file_path =~ s//\//\/gi; #---- Output format needed #$file_path ="\\abc.com\a\t\temp\L\"; printf $file_path; ...