Regular expression issue - ajaxcontroltoolkit

what is regular expression validator for the textbox which doesnot contains character like "< >" as a string input

<[^<]+?>
This Regex will match "< >" pair.
Add logic to your code to handle situation when this match is found

Related

SCALA Replace with $

I want replace a Letter with a literal $. I tried:
var s = string.replaceAll("Register","$10")
I want that this text Register saved to be changed to: $10 saved
Illegal group reference is the error I get.
If you look at the scaladoc for replaceAll, you'll see that it takes a regular expression string as the parameter. Escape the $ with a \, or use replaceAllLiterally
replaceAll uses a regular expressions to find the match. In the replacement string $ is a special character that refers to a specific capture group in the matching string. You have no capture groups so this is an error. It's not what you want anyway since you want the literal text "$10".
Usereplaceinstead ofreplaceAll`. It just does a direct string replacement.

Extract anchor tag link text using Powershell

I'm attempting to extract the link text from something like the line below using PowerShell.
Entertainment, Intimate Apparel/Swimsuit, and Suspicious
I've tried the following but it's only matching the first result and is including the > and < which I don't want. I'm sure it's an issue with the Regex but I don't know it well enough to see what's wrong. Note the string above is $result.categorization
$result.categorization -match '(\>(.*?)\<)'
This returns
Name,Value
2,Entertainment
1,>Entertainment<
0,>Entertainment<
I want to return
Name,Value
2,Suspicious
1,Intimate Apparel/Swimsuit
0,Entertainment
I also tried the Regex listed Regular expression to extract link text from anchor tag but that didn't match on anything.
I don't know where the headers and numbers in the output come from, but here's a solution that extracts the link texts from the single-line input exactly as specified:
$str = #'
Entertainment, Intimate Apparel/Swimsuit, and Suspicious
'#
$str -split ', and |, ' -replace '.*?>([^<]*).*', '$1'
$str -split ', and |, ' splits the input line into individual <a> elements.
-replace then operates on each <a> element individually:
'.*?>([^<]*).*' matches the entire line, but captures only the link text in the one and only capture group, (...).
Replacement text $1 then replaces the entire line with what the capture group matched, i.e., effectively only returning the link text.
As for what you tried:
-match never extracts part of its input - it returns a Boolean indicating whether a match was found with a scalar LHS, or a filtered sub-array of matching items with an array as the LHS.
That said, the automatic $Matches variable does contain information about what parts matched, but only with a scalar LHS.
'(\>(.*?)\<)' contains two nested capture groups that match literal > followed by any number of characters (matching non-greedily), followed by literal <.
It is the inner capture group that would capture the link text.
However:
There is no need for the outer capture group.
> and < do not need \-escaping in a regular expression (although it does no harm).

split string with "."

I am trying to split a string with "." but getting nothing in the array. File name is "Head-First-Java-2nd-edition.pdf" After splitting I want to extract extension, but don't know why it is giving blank array.
my #fileInfo = split(/./, $filename);
&logMsg("Array is: #fileInfo");
The split is giving an empty list because you are splitting on a wildcard .. Period is a meta character, and if you want to split on a literal period, you need to escape it
my #fileInfo = split(/\./, $filename);
Also, the syntax for calling a subroutine is NAME(LIST). Using the & prefix has a certain hidden feature, in that it circumvents prototypes. Read more in perldoc perlsub.
. in a regular expression means any character except \n. To split on a literal ., you need to escape it:
split /\./, $filename;

How to replace a character with null

I have one string
"8.53" I want my resulting string "853"
I have tried
the following code
tr|.||;
but its not replacing its giving 8.53 only .
I have tried another way using
tr|.|NULL|;
but its giving 8N53 can anyone please suggest me how to use tr to replace a character with NULL.
Thanks
You need to specify the d modifier to delete chars with no corresponding char:
tr/.//d;
Or you could use the (slower but more familiar) substitution operator:
s/\.//g;
You don't want tr because that transliterates characters from the 1st list with the corresponding character in the 2nd list (which was N in your example since that was the first character). You'll want the substitution operator.
my $var = "8.53";
$var =~ s/\.//;
print $var;
Add the g flag if there are multiple instances you want to replace (s/\.//g).

regexkitlite expression

I have to replace the following in a NSURL:
a_token=lksjadfkj%2gf98273984
with
a_token=new_token
a token can be in the follwing forms:
a_token=989asaofiusaodifusa9f789asdofu&lat=43.3
a_token=lksjadfkj%2gf98273984
So it either ends with & or end line/nothing.
How could I write the regex expression for it?
Thanks!
You could try:
[stringWithURL stringByReplacingOccurrencesOfRegex:#"(?<=a_token=)[^&]*"
withString:#"new_token"];
I haven't tested it. Basically, the regex uses a look-behind assertion to match a_token=. The look-behind is not included in the text that is matched. Then, the regex matches "zero or more characters that aren't &".