regex

Formatted string parsing and updating

I need to replace specialy marked place holders in string with values. Similar to what string.Format does, but in a bit more advance way. For instance: input string: "Welcome to {Binding Path=@city}!" Value for @city is "Boston" Output string should be "Welcome to Boston!". I can successfully parse input string with regex and get th...

Javascript RegExp Result

If you use the regular expression /(this|a)/ Now if I have: var text = "this is a sentence."; text = text.replace(/(this|a)/gi, "_"); document.write(text); I get the output: _ is _ sentence I am working on a piece of Javascript that does selective styling so what I want to do is add '<span class="className">" + word_in_regex + "</sp...

how to truncate a string using regular expression in perl

I have the following string in a file and want to truncate the string to no more than 6 char. how to do that using regular expression in perl? the original file is: cat shortstring.in: <value>[email protected]</value> <value>[email protected]</value> I want to get file as: cat shortstring.out <value>1234@g</value> ...

My regular expression allows spaces when formatting phone number.

I have the following regex being used in javascript. phone_number.match(/^1-\d{3}-\d{3}-\d{4}$/); it works great with one exception. It allows spaces. I want to strictly format 1-xxx-xxx-xxxx but it allows 1- xxx-xxx-xxxx anyone have any ideas how I can NOT allow spaces? ...

Netbeans Multi-line Regular Expression Search

I'm trying to search for all the HTML input tags with a type of 'text' inside Netbeans 6.9. Does Netbeans support searching for string using regular expressions with different search criteria spread across multiple lines or does it only work within a single line? This regular expression <input.*type=['"]text['"].*/> works when the ...

Grep for .PO file, or RegEx for a block of text between delimiters

Start with this file: msgid "a string" msgstr "" msgid "" "A longer string wraps " "on multiple lines." msgstr "" Grep RegEx to replace all msgstr lines like this: msgid "a string" msgstr "{a string}" msgid "" "A longer string wraps " "on multiple lines." msgstr "" "{A longer string wraps " "on multiple lines.}" In my infinite ...

Regex: Extract http and title attributes from anchor tag with PHP

I have a bunch of URLs structured like so <h4 class="classname"><a href="http://some-website.com" onclick="someVaryingJS();" title="Some Title">Some Title</a><h4> I want to be able to extract just the href and title attributes, keeping in mind the onclick attribute changes per tag and that I only want to do it for anchor tags that are...

Using Regex in Yahoo pipes to "clean" RSS feeds...

Hi, everyone. Need some help in creating a Yahoo Pipe that strips certain elements from an rss feed. To clerify: I would use the regex code on Yahoo Pipes. I presume the regex syntax is universal? I've broken the question up to some sub-questions: What would be the regex for removing/striping a specific html tag (has its own class)?...

Is it possible for a regex to know whether a date is a weekend or not?

Using javascript I need to validate a form field containing a date in the format: 21/04/2010. The date must be a weekday. Is it possible to create a regular expression for this or is there another, better way to do it? ...

Selecting text from between two separate strings + php

Hi there, I've got a string of data, and I want to remove the content between two blocks of text using PHP. Here's an example: "dataset123" The text I want is here. "endfile" I want everything between those two quoted values. The values won't change, so they can be hard coded. Any ideas? I've tried searching for something like this...

Pattern, matcher in Java, REGEX help

I'm trying to just get rid of duplicate consecutive words from a text file, and someone mentioned that I could do something like this: Pattern p = Pattern.compile("(\\w+) \\1"); StringBuilder sb = new StringBuilder(1000); int i = 0; for (String s : lineOfWords) { // line of words is a List<String> that has each line read in from txt fil...

Add suffix to a file name

$config['file_name'] = preg_replace('/(\.gif|\.jpg|\.png)/', '_thumb$1', $filename); Basically I want filename.jpg to become filename_thumb.jpg I don't understand why but the extension is being repeated twice. (filename.jpg.jpg). Edit This does work, I have other problems in my code. ...

Need regex to match two rather similar URL patterns

Hello all, I need a regex (to be used in .htaccess) with the following attributes, capturing the four-digit number and the text following it: Match: /9876/text_text_more_text_still_more_text /8765/1234_text_text_text Do not match: /2010/08/01/text_text_more_text_still_more_text /2010/08/01/text-text-more-text-still-more-text So far I...

Breaking a location.hash into an array using Regex

I'm trying to break a location.hash into an array using a RegEx. I can't for the life of me get the RegEx right. the location.hash can be either "#/A/B/C/D" or "#/A/B/C/D/" and must break down into "A", "B", "C", "D". ...

regex split implementation for sql server

hi I have created a function to implement the regex.split in sql. Here's the code: private static IEnumerable<IndexedValue<T>> ToIndexedValue<T>(IEnumerable<T> list) { int idx = 1; foreach (T value in list) yield return new IndexedValue<T>(++idx, value); } private struct IndexedValue<T> { public int Index; public T Value; ...

Regex match take a very long time to execute

Hello, I wrote a regular expression that parses a file path into different group (DRIVE, DIR, FILE, EXTENSION). ^((?<DRIVE>[a-zA-Z]):\\)*((?<DIR>[a-zA-Z0-9_]+(([a-zA-Z0-9_\s_\-\.]*[a-zA-Z0-9_]+)|([a-zA-Z0-9_]+)))\\)*(?<FILE>([a-zA-Z0-9_]+(([a-zA-Z0-9_\s_\-\.]*[a-zA-Z0-9_]+)|([a-zA-Z0-9_]+))\.(?<EXTENSION>[a-zA-Z0-9]{1,6})$)) I made a...

pratical example of Postgres regex substring or regexp_matches

I have been trying to figure the following for a couple days. Please HELP PostgreSQL table : locations Id State -------------------- 1 New York 2 Texas input = 'Greetings from Texas to all Cowboys' output: row containing Texas SELECT id, state FROM locations WHERE state ~* substring(input from state) ...

Regex Negative Lookahead

I'm trying to write a very simple regular expression that matches any file name that doesn't end in .php. I came up with the following... (.*?)(?!\.php)$ ...however this matches all filenames. If someone could point me in the right direction I'd be very grateful. ...

I have to extract a word in perl...using regular expression

The word starts with -D(It may be d also) Followed with..IT may contain spaces or do on not caontain After that its Followed by a $ Then the series is{rajna_NAME} To be brief -d ${ranjana_wdgf_NAME}or -D${Tom_task_NAME} i want to extract ranjana_wdgf Tom_task My doubt is if($word =~m/^-D(\$)\|(\w*NAME)\b/) Whats wrong: Please pr...

Replace Dot(.) with Comma(,) using RegEx?

I am working on ASP.NET (C#) application. I want to change number decimal figure with comma(,) where i have dot(.) using regular expression. For example: Price= 100,00.56 As this international rule of representing numeric values but I Sweden they have different ways for numbers Like Price= 100.00,56 So i want to change dot(.) in...