regex

Regex: remove line breaks from parts of string (PHP)

I want to remove all the line breaks and carriage returns from an XML file so all tags fit on one line each. XML Source example: <resources> <resource> <id>001</id> <name>Resource name 1</name> <desc>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas nibh magna, fermentum et pretium vel, malesuada sit amet ...

php string to variable

I have built variable $line based on the following: foreach ($regex as $each){ $parts = explode('::',$each); $pattern = '"/^'.$parts[1].'/i"'; $subject = '$row['.$parts[0].']'; $line .= 'preg_match'.'('.$pattern.','.$subject.')'; if (end($regex) != $each){ $line .= '&&'; } } I have a function that call the $line. Once called, ...

Convert Carrage returns to br tags

Hi All, I'm stuck with a small problem of parsing carrage return in a text area. JQuery Code $.fn.escapeHtml = function() { this.each(function() { $(this).html( $(this).html() .replace(/"/g,"&quot;") .replace(/&/g,'&amp;') .replace(/</g,'&lt;') .rep...

Using C#, how to search and enter a hyperlink in a block of text?

For some reason I can't find this through searches, not really sure what keywords to use. In my web app, users enter text into plain text boxes. I want to automatically convert any http://somekind.oflink.com to an html anchor tag for them. What's the best way to capture the link? I only want to support links that start with "http://". ...

What regex to use for replacing lines in a xml file

I have a large number of records of the following type, which I have to modify I would like to remove the created_by="29" line without leaving a space. Note: A wild card inside the created_by value would be preferable I would like to remove the entire line creation_date="..." and the /> greater should move after state="1"/> Insert a ne...

URL routing process works on one web, not another. 100% processor usage.

Hi, I thought I have URL routing under control as it works well on one website but found out it is not working fine on another. Both websites run from same server, same IIS 6.0, same asp_isapi.dll. SETUP 1: This one works well: routes.MapPageRoute("Article SEO", "sid/{sid}", ...

In a makefile, how to get the relative path from one absolute path to another?

An example to illustrate my question: Top level makefile rootdir = $(realpath .) export includedir = $(rootdir)/include default: @$(MAKE) --directory=$(rootdir)/src/libs/libfoo Makefile for src/libfoo currentdir = $(realpath .) includedir = $(function or magic to make a relative path from $(currentdir) to $(includ...

Extract a specific portion of connection string

Hello, Any way to extract what's after the @(if any) and before the next . (if any)? Examples: host host.domain.com user@host first.last@host [email protected] [email protected] I need to get host in a variable. Suggestions in Python? Any method is welcomed. Thanks, EDIT: I fixed my question. Need to match host and h...

Replace Bad words using Regex

I am trying to create a bad word filter method that I can call before every insert and update to check the string for any bad words and replace with "[Censored]". I have an SQL table with has a list of bad words, I want to bring them back and add them to a List or string array and check through the string of text that has been passed i...

Simple C# regex question

Question: What's the simplest way how to test if given Regex matches whole string ? An example: E.g. given Regex re = new Regex("."); I want to test if given input string has only one character using this Regex re. How do I do that ? In other words: I'm looking for method of class Regex that works similar to method matches() in class M...

Adding html tags with Java based on regex, keeping data in matches

Using java, I am writting a script to anchor link an html bibliography. That is going from: [1,2] to: <a href="o100701.html#bib1">[1, 2]</a> I think I have found the right regex expression: \[.*?\] What I am having trouble with is writting the code that will retain the values inside the expression while surounding it with the link ta...

What is the pattern for empty string?

I need to validate input: valid variants are either number or empty string. What is the correspondent regular expression? String pattern = "\d+|<what shoudl be here?>"; UPD: dont suggest "\d*" please, I'm just curious how to tell "empty string" in regexp. ...

finding a number in filename using regex

I don't have much experience with regexes and I wanted to rectify that. I decided to build an application that takes a directory name, scans all files (that all have a increasing serial number but differ subtly in their filenames. Example : episode01.mp4, episode_02.mp4, episod03.mp4, episode04.rmvb etc.) The application should scan the...

Change a relative URL to absolute URL

hi everyone. for example i've got a string like this: $html = ' <a href="test.html">test</a> <a href="http://mydomain.com/test.html"&gt;test&lt;/a&gt; <a href="http://otherdomain.com/test.html"&gt;test&lt;/a&gt; <a href="someothertest/otherdir/hi.html">hi</a> '; and i want to ap...

Replace the leading space with &nbsp; with same number of times using PHP regex

Hi, I want to replace leading space with &nbsp; same number of occurrences i.e. Bit explanatory : If one leading space exist in input then it should replace with one &nbsp; If two leading spaces exist in input then it should replace with two &nbsp; If n leading spaces are exist in input then it should replace with exact n number of ...

What's wrong with this javascript function?

I am using the following javascript regex email validate function but it doen't seem to work why.... function IsValidEmail(email) { var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; return filter.test(email); } function forgetpassword() { if (document.getEle...

How to extract multiple patterns from txt doc.

I have a text document that lists urls with their subject and an email address. I need to extract all urls with their subject and the email address and put this all into a csv file. I just need to know how I can use regex to do this. Currently I am able to extract all urls but I need the email and subject associated with them. This is wh...

Perl RegEx: Limiting the pattern to only the first occurrence of a character

I am trying to extract the content of a date element from many ill-formed sgml documents. For instance, the document can contain a simple date element like <DATE>4th July 1936</DATE> or <DATE blaAttrib="89787adjd98d9">4th July 1936</DATE> but can also as hairy as: <DATE blaAttrib="89787adjd98d9">4th July 1936 <EM>spanned across mu...

RegEx for parsing SQL query in C#

I need to write RegEx in C# to parse SQL join query which is given as a string. Can somebody please help me because I'm new at this. Thanks a lot this is my problem: string query = @"SELECT table1.column1, table1.column2, table2.coulmn1, table2.column2 FROM table1 INNER JOIN table2 ON table1.column5 = table2.column5"; ...

what am I missing in this RegEx?

I'm trying to create a JavaScript Regex to test for: a valid # between 0 and 99.9 (where only a single decimal digit is allowed) e.g. 3.45 is not valid. so, blank is ok, any integer between 0 and 99 is ok, and a decimal value is allowed. I have this so far, but it is allowing values like 3.45 to pass: $^|$[0-9][0-9]?^|$[0-9][0-9]?.[0...