sm1994
sm1994

Reputation: 355

Python Regex match character before or after slash

I want to write a regex which matches strings based on the following:

Sample input looks like

Artifacts path 'artifacts_tube/AtomInstall*/**' not found.     // 1 match
</root>                                                        // 0 matches
Failed steps: [<DF2 [D:/Users/work/tmp/assets/dummyfailer]>]   // 1 match
Options : *.* /NS /NC /NDL /COPY:DAT /NP /MT:32 /R:11 /W:30    // 0 matches
Copy Dir: D:/Users/tempdir/tmp8fo -> D:/Users/tempdir/tmpj7xj  // 2 matches

I have a simple regex but it does not meet all of the above criteria \S*\/\S*. Output for my regex

Artifacts path 'artifacts_tube/AtomInstall*/**' not found.     // 1 match
</root>                                                        // 1 match
Failed steps: [<DF2 [D:/Users/work/tmp/assets/dummyfailer]>]   // 1 match
Options : *.* /NS /NC /NDL /COPY:DAT /NP /MT:32 /R:11 /W:30    // 8 matches
Copy Dir: D:/Users/tempdir/tmp8fo -> D:/Users/tempdir/tmpj7xj  // 2 matches

Upvotes: 1

Views: 684

Answers (2)

sahinakkaya
sahinakkaya

Reputation: 6056

This is not exactly what you asked for (it allows : and * to occur anywhere in the path) but I think you can achieve your goal with it.

(?!\/[^:*])(?![^:*]\/)[\w\/*:]*\/[\w\/*:]*

Regex 101 Demo

Upvotes: 1

ItsByteMe
ItsByteMe

Reputation: 140

This regex should work for what you need

[*:](?!\s)\/[\s]*[:*]*

https://regex101.com/r/nI18g9/1

Upvotes: 1

Related Questions