regex

Regular expression to match an ldap connection string

Hi all, I need to extract information from an LDAP connection string like this one: ldap://uid=adminuser,dc=example,c=com:[email protected]/dc=basePath,dc=example,c=com I want to use a regular expression that will extract each token for me and place it in an array. I tried some regex expression and the best I got was this: /(\...

How can I extract a file path from a Perl string?

I want to find the file name with fullpath from this string "[exec] /snschome/sns/ccyp/mb_ccsns/bb/cbil5/v85_8/amdocs/iamcust/bil/cl/business/handlers/ClReportsHandler.java:233: cannot resolve symbol" I want to extract /snschome/sns/ccyp/mb_ccsns/bb/cbil5/v85_8/amdocs/iamcust/bil/cl/business/handlers/ClReportsHandler.java and I a...

Removing incomplete P Tags (using REGEX or any other method)

hi, my problems is a bit case specific , first of all, Its only for <p>tags not for any other tag.So you need not worry about any other tag. I am having html document which is a output of one software ,but it has some errors like unclosed <p> tags. eg. I have taken all document in a string my document is like .. <html> .....

Javascript RegExp replace with negative lookahead

Hi, I am trying to replace some value in the query string of the current page using JS. Eg: from category=Old Value to category=New Value. To code looks like this: var sNewValue = 'New Value'; sQueryString = sQueryString.replace(/category=[^&]+&?/, 'category=' + sNewValue); It works fine except for values that have ampersands. Luckil...

Is Regex for Form Validation if I use the following?

I know there is no harm in adding it either way but I'm curious... If I was to use htmlentities(); with ENT_QUOTES and then mysql_real_escape_string(); the variable before entering it into the Database, then just use html_entity_decode(); along with stripslashes(); to display the information... Would this still be safe and secure? ...

Can Someone explain this reg ex to me?

I recently asked a question on formatting a telephone number and I got lots of responses. Most of the responses were great but one i really wanted to figure out what its doing because it worked great. If phone is the following how do the other lines work...what are they doing so i can learn $phone = "(407)888-9999"; $phone = preg_re...

How can I recognize Windows file paths in a string in Perl?

I have been doing some searching for a regex that can be used as a rule to disallow users entering windows file paths without escaping the "\". So far I have found this expression [^\\]*$ However, this fails for the following: C:\\Program Files\\testing By fails I mean that it does not validate this string. Any he...

Split Ruby regex over multiple lines

This might not be quite the question you're expecting! I don't want a regex that will match over line-breaks; instead, I want to write a long regex that, for readability, I'd like to split onto multiple lines of code. Something like: "bar" =~ /(foo| bar)/ # Doesn't work! # => nil. Would like => 0 Can it be done? ...

PHP: regex & hash key in string

How do I address special characters in Regex? @ ? # $ % %... this patten searches for a letter that comes between a prefix and a suffix. $pattern = '/((?<!\b$PREFIX)$LETTER|$LETTER(?!$SUFFIX\b))/i'; $string = 'end'; $prefix = 'e'; $letter = 'n'; $suffix = 'd'; But what if $string began with a # $string = '#end'; $prefix = ?...

How to adjust my regex to work with multiline and more complex text?

Background: I've wrote a small library that is able to create asp.net controls from a string. Sample text: Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et {{asp:hyperlink|NavigateUrl="/faq.aspx";Text="FAQ";}} {...

Understanding regex in Java: split("\t") vs split("\\t") - when do they both work, and when should they be used..

Hi, I have recently figured out that I haven't been using regex properly in my code. Given the example of a tab delimited string str, I have been using str.split("\t"). Now I realize that this is wrong and to match the tabs properly I should use str.split("\\t"). However I happen to stumble upon this fact by pure chance, as I was looki...

Javascript regex assistance

I have the following javascript regex... .replace("/^(a-zA-Z\-)/gi", ''); It isn't complete... in fact it's wrong. Essentially what I need to do is take a string like "XJ FC-X35 (1492)" and remove the () and it's contents and the whitespace before the parenthesis. ...

Returning all characters before the first underscore

Hello, Using re in Python, I would like to return all of the characters in a string that precede the first appearance of an underscore. In addition, I would like the string that is being returned to be in all uppercase and without any non-alpanumeric characters. For example: AG.av08_binloop_v6 = AGAV08 TL.av1_binloopv2 = TLAV1 I a...

PHP - Function To Find Links In Text

I have got a function that converts strings like 'www.example.com' and 'http://example.com' in hyperlinks. It also deals with subdomains e.g. 'http://sub.example.com'. But it fails with this one - http://www.example.com' and outputs the following <a href="http://&lt;a href="http://www.chemica.ru"&gt;www.chemica.ru&lt;/a&gt;"&gt;http://...

How can I determine if a value is in a Perl array?

I'm using this small snippet to determine whether or not a URL is currently being stored in an array: if( $self->{_local} eq "true" && ! grep {m|^$new_href?$|} @m_href_array ) { push( @m_href_array, $new_href ); push( @href_array, $new_href ); } It seems to work but then my code throws an error saying: Sequence (?$...) not im...

How do I set up a HTTP to HTTPS redirection for a specific domain in lighttpd?

I would like to redirect specific domains from http to the corresponding https address in lighttpd. I tried out the tutorial on the lighttpd page but there it is not written for a specific domain. This is what I want: $HTTP["host"] =~ "secure.example.com" { server.document-root = "/var/www/secure.example.com" // IF NOT SSL, RE...

PHP: remove extra space from a string using regex

How do I remove extra spaces at the end of a string using regex (preg_replace)? $string = "some random text with extra spaces at the end "; ...

Can MySQL do regular expression substitution in an UPDATE?

I've seen MySQL SELECT examples using the REGEXP operator for matching. Is there a way to do regular expression substitution in an UPDATE? If not, what's the simplest method to run a regex substitution on all values in a column? Feel free to suggest using any programming language or regex implementation. ...

JavaScript Regular Expression to validate an address

I am trying to modify this script to accept , - and ' for this regex to validate addresses on a form is it written correctly? ^[a-zA-Z0-9\s\,\''\-]*$ ...

Find occurrences of characters in a Java String

Hello, I would like to count the occurrences of a character in a string, suppose I have the string "aaaab", how would i count the amount of a's in it? ...