Click here to Skip to main content
15,880,503 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
QuestionSometimes its a bullet item, sometimes it is not, sometimes it is multiple bullet items Pin
Member 158838933-Jan-23 22:31
Member 158838933-Jan-23 22:31 
AnswerRe: Sometimes its a bullet item, sometimes it is not, sometimes it is multiple bullet items Pin
OriginalGriff3-Jan-23 22:37
mveOriginalGriff3-Jan-23 22:37 
GeneralRe: Sometimes its a bullet item, sometimes it is not, sometimes it is multiple bullet items Pin
Member 158838933-Jan-23 23:14
Member 158838933-Jan-23 23:14 
QuestionRegEx- Find files in Linux which match the expression Pin
JDMils3-Jan-23 16:16
JDMils3-Jan-23 16:16 
AnswerRe: RegEx- Find files in Linux which match the expression Pin
Richard MacCutchan3-Jan-23 21:32
mveRichard MacCutchan3-Jan-23 21:32 
AnswerRe: RegEx- Find files in Linux which match the expression Pin
k50544-Jan-23 9:12
mvek50544-Jan-23 9:12 
GeneralRe: RegEx- Find files in Linux which match the expression Pin
JDMils8-Jan-23 12:56
JDMils8-Jan-23 12:56 
QuestionRegular Expression to find parts of a <script/img src=""> or <link href=""> attribute value Pin
Steve M Penner3-Jan-23 5:13
Steve M Penner3-Jan-23 5:13 

Regular Expression to find parts of a <script/img src=''> or <link href=''> attribute value


Been using my go-to regex101.com editor to work this out, but I always have problems with URLs and filesystem paths. I generally have the 'https' URL/resource in order.

I am trying to read and parse the link 'href' and img/script 'src' attribute values from the elements extracted in the markup.

The groupings/captures I want are
  1. "path provider" (PowerShell terminology), basically the drive
  2. The path leading to the file part. I prefer groupings between the path separator "\" or "/", both must be accounted for but will accept a long string
    Thus, suppose D:\a\b\c\file.ext
    This part can be grouped as '\a\b\c' but if it can multiple groups '\a', '\b', '\c', even better.
    One more more path separators required
  3. The file basename without path separator
  4. The file extension with the leading '.' which is the last '.' of the path
My working pattern/RE is: ^([a-zA-Z] ?(([/\]?[^/\]+)*)[/\]([^.]+).(\S+)$

The pattern might be more specific regular expressions separated by the alternative separator (|) instead of trying to match the strings with a single expression.

I specifically include the '^' and '$' start and end assertions for the markup attribute value.

Test string #1: ${SPREST_JS_FolderPath}/SPListREST.js

  • No path provider/drive, so no Group 1 - OK
  • Group 2: ${SPREST_JS_FolderPath} # Item (ii)
  • Group 3: ${SPREST_JS_FolderPath} # repeat of Group 2 -- not wanted
  • Group 4: SPListREST # file basename Item (iii)
  • Group 5: js # file type/extension Item (iv)

Test string #2 D:\dev\SharePoint\SPTools\src\pagestyle.css

  • Group 1: D: # Item (i)
  • Group 2: \dev\SharePoint\SPTools\src # Item (ii) exactly as required if groupings by '\pathseg' not possible
  • Group 3: \src # the last path segment--unwanted
  • Group 4: pagestyle # file basename Item (iii)
  • Group 5: css # file type/extension Item (iv)

Test string #3 ./js/SPREST/SPRestEmail.js

  • No path provider/drive, so no group 1
  • Group 2: ./js/SPREST # Item (ii) exactly as required if groupings by '\pathseg' not possible
  • Group 3: /SPREST # the last path segment--unwanted
  • Group 4: SPRestEmail # file basename Item (iii)
  • Group 5: js # file type/extension Item (iv)
[composed in Markdown, so presentation affected by your settings/stylings]
QuestionParsing Session Campaign Data in Data Studio Pin
Michael Oct20223-Jan-23 3:16
Michael Oct20223-Jan-23 3:16 
AnswerRe: Parsing Session Campaign Data in Data Studio Pin
Michael Oct20223-Jan-23 5:01
Michael Oct20223-Jan-23 5:01 
QuestionNeed a bit of help concerning RegEx Pin
Regis Maltais 202112-Dec-22 23:42
Regis Maltais 202112-Dec-22 23:42 
AnswerRe: Need a bit of help concerning RegEx Pin
OriginalGriff12-Dec-22 23:47
mveOriginalGriff12-Dec-22 23:47 
QuestionWhy does this work but this doesn't Pin
Andrew St. Hilaire26-Nov-22 16:52
Andrew St. Hilaire26-Nov-22 16:52 
QuestionRe: Why does this work but this doesn't Pin
k505426-Nov-22 17:30
mvek505426-Nov-22 17:30 
AnswerRe: Why does this work but this doesn't Pin
Andrew St. Hilaire26-Nov-22 17:51
Andrew St. Hilaire26-Nov-22 17:51 
AnswerRe: Why does this work but this doesn't Pin
Richard Deeming27-Nov-22 22:11
mveRichard Deeming27-Nov-22 22:11 
AnswerRe: Why does this work but this doesn't Pin
jschell28-Nov-22 10:42
jschell28-Nov-22 10:42 
QuestionHow to remove an & in the following expressions Pin
Victor Nijegorodov21-Nov-22 8:31
Victor Nijegorodov21-Nov-22 8:31 
AnswerRe: How to remove an & in the following expressions Pin
k505421-Nov-22 10:21
mvek505421-Nov-22 10:21 
GeneralRe: How to remove an & in the following expressions Pin
Victor Nijegorodov22-Nov-22 3:32
Victor Nijegorodov22-Nov-22 3:32 
AnswerRe: How to remove an & in the following expressions Pin
Richard MacCutchan21-Nov-22 21:50
mveRichard MacCutchan21-Nov-22 21:50 
GeneralRe: How to remove an & in the following expressions Pin
Victor Nijegorodov22-Nov-22 2:41
Victor Nijegorodov22-Nov-22 2:41 
GeneralRe: How to remove an & in the following expressions Pin
Richard MacCutchan22-Nov-22 3:13
mveRichard MacCutchan22-Nov-22 3:13 
GeneralRe: How to remove an & in the following expressions Pin
Victor Nijegorodov22-Nov-22 3:59
Victor Nijegorodov22-Nov-22 3:59 
AnswerRe: How to remove an & in the following expressions Pin
Victor Nijegorodov22-Nov-22 4:05
Victor Nijegorodov22-Nov-22 4:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.