• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Problem with Python, Regex search and string “/”

Resolved: Problem with Python, Regex search and string “/”

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have following string:
I would like to look for strings between “</transactionshares>” and “<transactionacquireddisposedcode>” by using:
But it outputs None, which is wrong. Expected output:
I tested the regex search string using regex101 and the output is correct: https://regex101.com/r/bVT6JU/1
I thought the search string “/” was the cause of this problem, therefore I tried using
<\/transactionshares>(.*)<transactionacquireddisposedcode>
Still I don’t get my expected output. Both of search strings work on regex101.
Thank you for any help.

Answer:

The \n is messing you up. adding flags=re.DOTALL will make your .* include the \n
&lt;\ntransactionPricePerShare&gt;
I also changed the .* to a .*? to make it less greedy, which you may want. That way it stops at the first <transactionacquireddisposedcode>

If you have better answer, please add a comment about this, thank you!

python regex
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Why reference in pointer array doesn’t have data?

24/03/2023

Resolved: EntityFramework creates/runs migrations using parameterless DataContext instance

24/03/2023

Resolved: Visual Studio 2022 crashes when using breakpoints

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.