Removing non-alphabetic characters in VBScript run from command line [closed] - regex

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm trying to remove all the non-alphabetic characters in a string in a VBScript that will run from the command line.
Here's what I have thus far:
Set wshShell = CreateObject("WScript.Shell")
Dim test
test = "Hello:, world!"
test = strClean(test)
WScript.Echo(test)
Function strClean(strVal)
Set objRegEx = CreateObject(“VBScript.RegExp”)
objRegEx.Global = True
objRegEx.Pattern = “[^A-Za-z\n\r]”
strSearchString = objRegEx.Replace(strVal, “”)
End Function
But I'm getting the following error:
my.vbs (8, 35) Microsoft VBScript compilation error: Invalid character

The quotes you're using are Unicode and are invalid.
You should replace them by ASCII ones.
This is a community answer from Slai's comment that doesn't want to write an answer.See this meta post for more info.

Related

Split a string to have individual quotes [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a string
abc = 'tea,coffee'
Want to split into ('tea','coffee')
I tried to split but the result is showing as double quotes in front and last
i am getting result as "tea','coffee"
#given string
abc = 'tea,coffee'
#splitting into array
result = abc.split(',')
#making tuple
tuple(result)
#printing result
print(result)
done!!

RegEx Splitting to a List<string> [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
RegEx is a bit confusing to me and I have been at it for 3.5 hours on one line.
I have a string:
" Layer 1 Layer 2 Layer 3 Layer 4 "
I would like to split it up into a List and cannot get it to work.
I tried this and it was close but still not what I am looking to do:
List<string> lineWords = Regex
.Matches(line, #"[Layier_]*\s*\s*[1-9]")
.OfType<Match>().ToArray()
.Select(match => match.Value)
.List();
Where am I in error?
Thank you.
You didn't write it explicitly, but I assume, you are using C#.
Your code requires only minor corrections:
I changed the regex a little (compare).
ToArray() is not needed.
Instead of List() use ToList().
So the code given below works.
List<string> lineWords = Regex.Matches(line, #"[Layier_]+\s*[1-9]")
.Cast<Match>()
.Select(match => match.Value)
.ToList();

Python3 Regex groupdict not working properly [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Using Python 3.4.3
I'm trying to do a regex to split CSS like identifiers. My pattern is:
pattern = re.compile("(?P<tag>[^.#]+)?(#(?P<iḍ>[^.#]+))?(?P<classes>([.][^.#]+)+)?")
My test string is h2#label. When I do the match, the groups I get are ('h2', '#label', 'label', None, None) which is correct.
If I get the groupdict of the match I get {'classes': None, 'iḍ': 'label', 'tag': 'h2'} which also looks correct. However, when I try to retrieve the value of id I get a result as if it's not present.
Doing "id" in match.groupdict() yields False and doing "match.groupdict().get("id")yieldsNone`.
Any idea what's wrong here and how to solve it?
You need to fix the typo: instead of 'iḍ' type 'id'.
pattern = re.compile("(?P<tag>[^.#]+)?(#(?P<id>[^.#]+))?(?P<classes>([.][^.#]+)+)?")

What is the right Regular Expression for my validation? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I created a RegEx-based validation with SO's help and passed it off to my coworker explaining the reasons why it is needed (Referring to it as a Whitelist). The coworker then proceeded to change my code (insisting upon what they called a Blacklist) and modified the RegEx. The code corresponding to each approach is listed below. The validation should ensure that only a hyphen, numbers, spaces and letters are allowed. I'd like to know
Which of the code fragments achieves that?
How can I break my co-worker's code?
Is a Blacklist just a Whitelist with the condition inverted?
My co-worker's Code:
objRegExp.Pattern= "[^-A-Za-z0-9'&(). ]"
if objRegExp.Test(strInput) then
FoundSpecialChar= true
exit function
end if
FoundSpecialChar= false
Set objRegExp = Nothing
My Code:
objRegExp.Pattern= "^[-A-Za-z0-9\s'&().]+"
if objRegExp.Test(strInput) then
FoundSpecialChar= false
exit function
end if
FoundSpecialChar= true
Set objRegExp = Nothing
Your colleague's approach lists the acceptable characters. If it finds even one character not in that list, it sets FoundSpecialChar= true which seems to be what you want. To test the difference between his code and yours, you could try to run both the code fragments with strInput = "ABCD#EFGH".
Running your code once with strInput = "A#" and another time with strInput = "#A" should help as well.
BTW, Set objRegExp = Nothing should be included before Exit Function as well.
I am from testing background and I've experienced that Whitelist approach is good from application developer point of view and Blacklist approach is good to test the application. The reason being, as a dev a Whitelist gives you control over the exact input that a user is allowed to enter. On the other hand, as a tester I would use the Blacklist approach more because it will have infinite number of options to test.
Interesting discussion on SO --> blacklisting vs whitelisting in form's input filtering and validation

RegEx ActionScript 3 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to figure out a regex to strip extra single quotes so that I would end up with only one single quote. To explain my question better, here is an example.
Let's say I have 3 different strings such as this ones.
(two single quotes)
Name<span fontSize=''16'' baselineShift=''superscript''>ABC</span>
(three single quotes)
Name<span fontSize='''16''' baselineShift='''superscript'''>ABC</span>
(four single quotes)
Name<span fontSize=''''16'''' baselineShift=''''superscript''''>ABC</span>
I am trying to sanitize the string to end up with this:
Name<span fontSize='16' baselineShift='superscript'>ABC</span>
I tried several online tools. This one is my favourite one: http://ryanswanson.com/regexp/#start. But I just can't get it right.
Could someone please help me out? Any tips and suggestions would be greatly appreciated.
Thank you in advance!
Did you try '+?
var str:String = "Name<span fontSize=''''16'''' baselineShift=''''superscript''''>ABC</span>";
trace( str.replace(/'+/g, "'") );
Have you looked at the docs for AS3's RegEx code? AS3 Replace
You could try something like this
var myPattern:RegExp = /'{2,100}/g;
var str:String = "fontSize=''''16''''";
trace(str.replace(myPattern, "'"));
The '{2,100} essentially looks for a match of ' that occurs between 2 - 100 times and replaces it with a single '.