Python3 Regex groupdict not working properly [closed] - regex

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>([.][^.#]+)+)?")

Related

How to use if else comparing string in a batch file? [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 months ago.
Improve this question
I would like to check the string is match or not. I tried this way, but it always return error, syntax error, I don't know which syntax that error.
Error message
The syntax of the command is incorrect.
if TXT EQU TXT(
SET Format=TXT
REM ECHO %Format%
if %Format% EQU TXT(
ECHO Format correct
GOTO END
)
ECHO Format not correct
This works for me:
#echo off
set format=TXT
if "%format%"=="TXT" (
#echo Format correct
goto :end
)
#echo Format not correct
:end

Regex for matching items from firewall syslog [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 2 years ago.
Improve this question
I am trying to come up with a regex to extract certain pieces of information from the below log. I've been messing with regex groups for awhile and am not getting anywhere. I would like to get the date/timestamp, the usr field, dstname field, and arg field. How can I accomplish this?
May 1 08:21:02 192.168.1.1 id=firewall sn=fakeserial time="2020-05-01 12:21:02 UTC" fw=1.2.3.4 pri=3 c=4 m=14 msg="Web site access denied" app=2515 sess="Auto" n=398533 usr="sampledomain\username" src=192.168.1.150:50334:X0 dst=72.21.81.240:80:X1 srcMac=b0:00:b4:18:4a:b5 dstMac=c0:ea:e4:9d:a0:8c proto=tcp/http dstname=ctldl.windowsupdate.com arg=/msdownload/update/v3/static/trustedr/en/disallowedcertstl.cab code=99 Category="Administrative Custom List settings" fw_action="drop"
You could base it on something like this
(\w{3} \d* [\d:]*).*usr="([a-z\\]*)".*dstname=([\w.]*).*arg=([\/][^ ]*)
https://regex101.com/r/VUIBAm/1

Delete String(s) Between Two Pattern Matches [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
I am trying to delete "PK WND 16026/1736" from the below text by removing any text between "RMK A02" and "SLP."
Text
KDFW 151753Z 17018G25KT 10SM FEW035 FEW120 SCT250 32/21 A2983 RMK AO2 PK WND 16026/1736 SLP093 T03220211 10322 20239 58008
Code
sed -e 's/\(RMK A02\).*\(SLP\)/\1\2/'
The above code doesn't appear to be working/deleting "PK WND 16026/1736."
Here is one way to do it:
awk -F"RMK AO2.*SLP" '{$0=$0~FS?$1"RMK AO2 SLP "$2:$0}1' file
KDFW 151753Z 17018G25KT 10SM FEW035 FEW120 SCT250 32/21 A2983 RMK AO2 SLP 093 T03220211 10322 20239 58008

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

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.

Replace the words "can't, don't" by "can not, do not" using python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
This post was edited and submitted for review 1 year ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I need to replace words like "{can't, don't, won't }" by "{can not, do not, would not}" using python
The problem is:
"can't" can be detected by checking suffix "n't", so we can replace "n't" by "not"
But how can we transform "ca" to "can" as when we split "can't" it should be transformed to "can not"?
Since the rules of English are large and sometimes inconsistent, your best bet is probably just to set up full word maps rather than trying to figure out on the fly which letters are represented by the apostrophe.
In other words, a dictionary with values like:
can't -> can not
don't -> do not
won't -> will not
:
oughtn't -> ought not