Hi,
I'm trying to create a regular expression for a user name.
Here are the rules
1) At least 8 characters and at most 50 characters
2) Allows A-Z, a-z, numbers, and any other character except / character.
Thank you,
-Tesh
...
I attempted to answer this question (answer deleted, so here is my code).
<?php
function remove_get_param($uri, $name) {
return preg_replace('/(?<=\?|&|;)' . preg_quote($name, '/') . '=[^&;]*/', '', $uri);
}
My initial code was consuming the first param such as ? when it shouldn't. I tried to do a lookbehind assertion b...
Hello. I need to find and replace substring with dot in it. It's important to keep search strict to word boundaries (\b). Here's an example script to reproduce (i need to match "test."):
<?php
# 1.php
$string = 'test. lorem ipsum';
if(!preg_match('~\btest\.\b~i', $string)) echo 'no match 1' . PHP_EOL;
if(!preg_match('~\btest\b\.~i', $st...
I want to remove all - and / characters in a date string. Can someone give me a hand?
Here is what I have but it doesn't work.
preg_replace('/','',$date);
preg_replace('-','',$date);
Also, is there a way to group these two expressions together so I don't have to have 2 preg_replaces?
...
hi there,
I'm trying to get the text between the heading tag using the following php script:
$search_string= < h1 >testing here< /h1 >;
$text = preg_match('<%TAG%[^>]*>(.*?)</%TAG%>',$search_string, $matches);
echo $matches[0];
When i try to run this script there is no value being returned. Instead there is warning message:
Warn...
I'm trying to find out what the algorithm would be by being given two languages L1 and L2 to determine if they are equivalent (L1 = L2).
It's surprisingly difficult to come up with one as I've found, although I am pretty sure it needs to be converted to a DFA first and then reduce each of them to a minimal DFA..
Also, I know that if L1...
Hello. I am working with ASP.NET and need to manage with a string typed by the user in order to extract some information. The user enters a normal text, words and numbers, but sometimes he may type a mathematical expression in MATHML, these expressions are always an xml string enclosed by the tag.
I want to extract from the typed text e...
how do i preserve sentences that start with X criteria and delete sentences that match Y criteria.
using vim, I would like to delete all sentences that do not start with void.
void set_first_name(string in_first_name);
string first_name();
void set_last_name(string in_last_name);
string last_name();
void set_composer_yob(in...
I'm using the following method to parse URLs:
Regex.Replace(text, @"((www\.|(http|https|ftp)\://)[.a-z0-9-]+\.[a-z0-9\/_:@=.+?,##%&~-]*[^.|\'|\# |!|\(|?|,| |>|<|;|\)])",
"<a href=\"$1\" target=\"_blank\">$1</a>", RegexOptions.IgnoreCase).Replace("href=\"www.", "href=\"http://www.");
It works great, but:...
The first character can be anything except '='.
I made the following RegEx:
[^=].
"ab", "b2" etc will pass. "=a" will not.
But the thing is, I also want to accept an empty character:
"a" should also be accepted. How can I do that?
Update
Sorry, the language is C#
You might wonder why I'm doing it. I have a URL RegEx
(?!=)((w...
I am trying to parse a wikitext file received through Wikipedia's API and the problem is that some of its templates (i.e. snippets enclosed in {{ and }}) are not automatically expanded into wikitext, so I have to manually look for them in the article source and replace them eventually. The question is, can I use regex in .NET to get the ...
I have a URL with the following format:
http://domain.com/checkout/nonce/701fe0f652/order/108/?token=EC-0DS37792JX3680821
I try to convert it into a clean URL using .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?token=(.*)$ /index.php/$1/token/$2/ [R...
I am looking for a Pythonic way to simplify this code:
fix = re.compile(r'((?<=>\n)(\t){2}(?=<))')
fixed_output = re.sub(fix, 1*2*' ', fixed_output)
fix = re.compile(r'((?<=>\n)(\t){3}(?=<))')
fixed_output = re.sub(fix, 2*2*' ', fixed_output)
# and so on...
That is: if there are n tab characters between ">" and "<", they are replaced ...
What reg expression patten to I need to match everything between {{ and }}
I'm trying to parse wikipedia, but im ending up with orphan }} after running the rexex code. Here's my PHP script.
<?php
$articleName='england';
$url = "http://en.wikipedia.org/wiki/Special:Export/" . $articleName;
ini_set('user_agent','custom agent'); //requi...
I need to extract a substring from a formatted value as follows:
“(The original reference for ‘item1’ is: 12345)”
The text that I need is 12345. ‘item1’ can change, although the rest of the string should remain static.
I currently have something like this:
string myString = “(The original reference for ‘item1’ is: 12345)”;
strin...
Hi all. I have this line as an example from a CSV file:
2412,21,"Which of the following is not found in all cells?","Curriculum","Life and Living Processes, Life Processes",,,1,0,"endofline"
I want to split it into an array. The immediate thought is to just split on commas, but some of the strings have commas in them, eg "Life and L...
Suppose we have a table:
Key|Val|Flag
01 |AAA| Y
02 |BBB| N
...
wrapped into xml this way:
<Data>
<R><F>Key</F><F>Val</F><F>Flag</F></R>
<R><F>01</F><F>AAA</F><F>Y</F></R>
<R><F>02</F><F>BBB</F><F>N</F></R>
...
</Data>
There can be more columns and rows, obviously.
Now I'd like to parse XML back to table using single regex...
Consider following script (it's total nonsense in pseudo-language):
if (Request.hostMatch("asfasfasf.com") && someString.existsIn(new String[] {"brr", "hrr"})) {
if (Requqest.clientIp("10.0.x.x")) {
somevar = "1";
}
somevar = "2";
}
else {
somevar = "first";
}
string foo = "foo";
// etc. etc.
How would you gr...
Hi all,
I have tried approximately every possible combination of RegexOptions.MultiLine and escaped backslashes in order to split a text using \ as a separator.
I have this text:
The quick brown
Fox jumps\
Over the
Lazy dog\
I want to split it into
The quick brown
Fox jumps\
and
Over the
Lazy dog\
I have tried so far (togethe...
I have setup nginx 0.7.67 on Ubuntu10.10 along with php-cli . I'm trying to get my front-controller based PHP framework to run, but all pages except index.php give a 403 error.
Ex :
http://mysite.com/styles/style.css - 403 Forbidden
http://mysite.com/scripts/script.css - 403 Forbidden
http://mysite.com/index.php - Works
My /etc/ngin...