How can I 301 redirect any URL that starts with a number between 1 - 9999, for example
domain.com/12/something/anotherthing
domain.com/378/product/widgets
domain.com/2560
What tools are available in Python to assist in parsing a context-free grammar?
Of course it is possible to roll my own, but I am looking for a generic tool that can generate a parser for a given CFG.
I would like to convert any instances of a hashtag in a String into a linked URL:
#hashtag - should have "#hashtag" linked.
This is a #hashtag - should have "#hashtag" linked.
This is a [url=http://www.mysite.com/#name]named anchor[/url] - should not be linked.
This isn't a pretty way to use quotes - should not be linked.
Here is my current code:
String.prototype.parseHashtag = function() {
return this.replace(/[^&][#]+[A-Za-z0-9-_]+(?!])/, function(t) {
var tag = t.replace("#","")
return t.link("http://www.mysite.com/tag/"+tag);
});
};
Currently, this appears to fix escaped characters (by excluding matches with the amperstand), handles named anchors, but it doesn't link the #hashtag if it's the first thing in the message, and it seems to grab include the 1-2 characters prior to the "#" in the link.
Halp!
Hello all
I got this question which asks me to figure out why is it foolish to write a regular expression for the language that consists of strings of 0's and 1's that are palindromes( they read the same backwards and forwards).
part 2 of the question says using any formal mechanism of your choice, show how it is possible to express the language that consists of strings of 0's and 1's that are palindromes?
Perl has been one of my go-to programming language tools for years and years. Perl 6 grammars looks like a great language feature. I'd like to know if someone has started something like this for Ruby.
I need to improve on a regular expression I'm using. Currently, here it is:
^[a-zA-Z\s/-]+
I'm using it to pull out medication names from a variety of formulation strings, for example:
SULFAMETHOXAZOLE-TRIMETHOPRIM 200-40 MG/5ML PO SUSP
AMOX TR/POTASSIUM CLAVULANATE 125 mg-31.25 mg ORAL TABLET, CHEWABLE
AMOXICILLIN TRIHYDRATE 125 mg ORAL TABLET, CHEWABLE
AMOX TR/POTASSIUM CLAVULANATE 125 mg-31.25 mg ORAL TABLET, CHEWABLE
Amoxicillin 1000 MG / Clavulanate 62.5 MG Extended Release Tablet
The resulting matches on these examples are:
SULFAMETHOXAZOLE-TRIMETHOPRIM
AMOX TR/POTASSIUM CLAVULANATE
AMOXICILLIN TRIHYDRATE
AMOX TR/POTASSIUM CLAVULANATE
Amoxicillin
The first four are what I want, but on the fifth, I really need "Amoxicillin / Clavulanate".
How would I pull out patterns like "Amoxicillin / Clavulanate" (in fifth row) while missing patterns like "MG/5 ML" (in the first row)?
In a text, I would like to replace all occurrences of $word by [$word]($word) (to create a link in Markdown), but only if it is not already in a link. Example:
[$word homepage](http://w00tw00t.org)
should not become
[[$word]($word) homepage](http://w00tw00t.org).
Thus, I need to check whether $word is somewhere between [ and ] and only replace if it's not the case.
Can you think of a preg_replace command for this?
How can I convert some regular language to its equivalent Context Free Grammar(CFG)?
Whether the DFA corresponding to that regular expression is required to be constructed or is there some rule for the above conversion?
For example, considering the following regular expression
01+10(11)*
How can I describe the grammar corresponding to the above RE?
Hi
I am trying to import this:
http://en.wikipedia.org/wiki/List_of_countries_by_continent_%28data_file%29
which is of the format like:
AS AF AFG 004 Afghanistan, Islamic Republic of
EU AX ALA 248 Åland Islands
EU AL ALB 008 Albania, Republic of
AF DZ DZA 012 Algeria, People's Democratic Republic of
OC AS ASM 016 American Samoa
EU AD AND 020 Andorra, Principality of
AF AO AGO 024 Angola, Republic of
NA AI AIA 660 Anguilla
if i do
<? explode(" ",$data"); ?>
that works fine apart from countries with more than 1 word.
how can i split it so i get the first 4 bits of data (the chars/ints) and the 5th bit of data being whatever remains?
this is in php
thank you
I'm seeking a solution to splitting a string which contains text in the following format:
"abcd efgh 'ijklm no pqrs' tuv"
which will produce the following results:
['abcd', 'efgh', 'ijklm no pqrs', 'tuv']
In other words, it splits by whitespace unless inside of a single quoted string. I think it could be done with .NET regexps using "Lookaround" operators, particularly balancing operators. I'm not so sure about Perl.
Here's the code I'm running:
import re
FIND_TERM = r'C:\\Program Files\\Microsoft SQL Server\\90\\DTS\\Binn\\DTExec\.exe'
rfind_term = re.compile(FIND_TERM,re.I)
REPLACE_TERM = 'C:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\DTExec.exe'
test = r'something C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTExec.exe something'
print rfind_term.sub(REPLACE_TERM,test)
And the result I get is:
something C:\Program Files\Microsoft SQL Server@\DTS\Binn\DTExec.exe something
Why is there an @ sign?
Hi all.
I got an exception when executing this snippet code
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteUrl.Trim()))
{
using (SPWeb web = site.OpenWeb())
{
try
{
web.AllowUnsafeUpdates = true;
SPUser spUser = web.AllUsers[userName];
if (spUser != null)
{
SPGroup spGroup = web.Groups[groupName];
if (spGroup != null)
spGroup.AddUser(spUser);
}
}
catch (Exception ex)
{
this.TraceData(LogLevel.Error, "Error at function Named [AddUserToSPGroupWidget.AddUserToGroup] . With Error Message: " + ex.ToString());
}
finally
{
web.AllowUnsafeUpdates = false;
}
}
}
});
PLease guide me. Thanks in advance.
I have a regular expression for phone numbers as follows:
^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$
I have a mask on the phone number textbox in the following format: (___)___-____
How can I modify the regular expression so that it accommodates the mask?
i have array which values are user input like:
aa df rrr5 4323 54 hjy 10 gj @fgf %d
would be that array,
now i want to check each value in array
whether its numeric or alphabetic (a-zA-Z) or alphanumeric
and save them in other respective arrays
i have done:
my @num;
my @char;
my @alphanum;
my $str =<>;
my @temp = split(" ",$str);
foreach (@temp)
{
print "input : $_ \n";
if ($_ =~/^(\d+\.?\d*|\.\d+)$/)
{
push(@num,$_);
}
}
this works,
similarly i want to check for alphabet, and alphanumeric values
note: alphanumeric ex. fr43 6t$ $eed5 *jh
Does anyone have suggestions for detecting url's in a set of elements and converting them to links?
$$('#pad dl dd').each(function(s){
//detect urls and convert to a elements.
});
What is the most concise way to transform a string in the following format:
mysql:[/[/]][user[:pass]@]host[:port]/db[/]
Into a usuable PDO connection/instance (using the PDO_MYSQL DSN), some possible examples:
$conn = new PDO('mysql:host=host;dbname=db');
$conn = new PDO('mysql:host=host;port=3307;dbname=db');
$conn = new PDO('mysql:host=host;port=3307;dbname=db', 'user');
$conn = new PDO('mysql:host=host;port=3307;dbname=db', 'user', 'pass');
I've been trying some regular expressions (preg_[match|split|replace]) but they either don't work or are too complex, my gut tells me this is not the way to go but nothing else comes to my mind.
Any suggestions?
I am finding a lot of useful help here today, and I really appreciate it. This should be the last one for the day:
I have a list of the top 10 keywords per site, sorted by visits, by date. The records need to be sorted as follows (excuse the formatting):
2010-05 2010-04
site1.com keyword1 apples wine
keyword1 visits 100 12
keyword2 oranges water
keyword2 visits 99 10
site2.com keyword1 blueberry cornbread
keyword1 visits 90 100
keyword2 squares biscuits
keyword2 visits 80 99
Basically what I need to accomplish involves grouping, but I can't seem to figure it out. Am I heading down the right path, or is there another way to achieve this, or is it just impossible?
Ok... changing the question here... I'm getting an error when I try this:
SELECT COUNT ( DISTINCT mid, regexp_replace(na_fname, '\\s*', '', 'g'), regexp_replace(na_lname, '\\s*', '', 'g'))
FROM masterfile;
Is it possible to use regexp in a distinct clause like this?
The error is this:
WARNING: nonstandard use of \\ in a string literal
LINE 1: ...CT COUNT ( DISTINCT mid, regexp_replace(na_fname, '\\s*', ''...
http://www.chuckecheese.com/rotator.php?cheese=4&id=1
I want to take out the id, leaving the cheese to stand alone. I tried:
$qs = preg_replace("[^&id=*]" ,'',$_SERVER[QUERY_STRING]);
But that said I was using an improper modifier. I want to remove "$id=" and whatever number comes after it. Are regexp really as hard as they seem for me?
I want to change
<lang class='brush:xhtml'>test</lang>
to
<pre class='brush:xhtml'>test</pre>
my code like that.
<?php
$content="<lang class='brush:xhtml'>test</lang>";
$pattern=array();
$replace=array();
$pattern[0]="/<lang class=([A-Za-z='\":])* </";
$replace[0]="<pre $1>";
$pattern[1]="/<lang>/";
$replace[1]="</pre>";
echo preg_replace($pattern, $replace,$content);
?>
but it's not working. How to change my code or something wrong in my code ?
I have tried to remove the following tag generated by the AJAX Control toolkit.
The scenario is our GUI team used the AJAX control toolkit to make the GUI but I need to move them to normal ASP .NET view tag using MultiView.
I want to remove all the __designer: attributes
Here is the code
<asp:TextBox ID="a" runat="server" __designer:wfdid="w540" />
<asp:DropdownList ID="a" runat="server" __designer:wfdid="w541" />
.....
<asp:DropdownList ID="a" runat="server" __designer:wfdid="w786" />
I tried to use the regular expression find replace in Visual Studio using:
Find:
:__designer\:wfdid="w{([0-9]+)}"
Replace with empty space
Can any regular expression expert help?
I am writing a small windows script in javascript/jscript for finding a match for a regexp with a string that i got by manipulating a file.
The file path can be provided relative or absolute. How to find whether a given path is absolute/relative and convert it to absolute for file manipulation?