Hello everyone, can anyone please help me write a regex pattern to find text that matches any of the below condition: -
1. More than one consecutive capital letter
2. One or more than one consecutive capital letter followed by - or one or more digits
3. Group of more than one consecutive capital letter with one or more small letters in between, example, P&R, MenB
4. One or more than one consecutive capital letter in brackets
5. A group of letters with - in between and non whitspace at beginning and at end
6. One or more than one consecutive capital letter followed by a - followed by one or more digits
7. A small letter immediately followed by one or more capital letters
8. More than one consecutive capital letters with a / in between
Also, here are few exmples of abbreviations that I want the regex pattern to identify: COVID-19, COVID19, EU5, P&R, Q4, mRNA, pPCV, SARS-CoV-2, (CPI), PCV13, MenACWY, PCV10, G-ba, G-bA, N/A, P&MA, MenB
This will help
([A-Z]{2,})|([A-Z]+[-\d]+)|([A-Z][a-z]+([A-Z][a-z]+)*\b)|(\b[A-Z]+[\w\s]*\))|(\S+[-\w]*\S)|([A-Z]+-\d+)|([a-z][A-Z]+)|([A-Z]+\/[A-Z]+)
yes it will,
let me know if not.
@Raj It seems to be not working in powerpoint VBA. It is returning the entire Title and text from the last text box from the slides.
Below is the complete code I am using -
Sub FindAbbreviations()
Dim regex As Object
Set regex = CreateObject("VBScript.RegExp")
regex.Global = True
regex.Pattern = "([A-Z]{2,})|([A-Z]+[-\d]+)|([A-Z][a-z]+([A-Z][a-z]+)*\b)|(\b[A-Z]+[\w\s]*\))|(\S+[-\w]*\S)|([A-Z]+-\d+)|([a-z][A-Z]+)|([A-Z]+\/[A-Z]+)"
Dim sld As slide
Dim shp As shape
Dim txtBox As shape
For Each sld In ActivePresentation.Slides
Set txtBox = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 0, sld.Master.Height - 50, sld.Master.Width, 50)
txtBox.TextFrame.TextRange.text = ""
txtBox.TextFrame.TextRange.Font.Size = 12
For Each shp In sld.Shapes
If shp.HasTextFrame Then
Dim text As String
text = shp.TextFrame.TextRange.text
If shp.Type = msoTable Or shp.Type = msoPlaceholder Then
Dim matches As Object
Set matches = regex.Execute(text)
If matches.Count > 0 Then
Dim match As Object
For Each match In matches
Dim abbrev As String
abbrev = match.Value
If InStr(txtBox.TextFrame.TextRange.text, abbrev) = 0 Then
If txtBox.TextFrame.TextRange.text <> "" Then
txtBox.TextFrame.TextRange.text = txtBox.TextFrame.TextRange.text & ", " & abbrev
Else
txtBox.TextFrame.TextRange.text = abbrev
End If
End If
Next match
End If
ElseIf shp.Type = msoSmartArt Then
GetSmart shp, regex, txtBox
End If
End If
Next shp
Next sld
End Sub
Private Sub GetSmart(smart As shape, regex As Object, txtBox As shape)
Dim node As Object
For Each node In smart.SmartArt.AllNodes
If node.TextFrame2.HasText Then
Dim text As String
text = node.TextFrame2.TextRange2.text
Dim matches As Object
Set matches = regex.Execute(text)
If matches.Count > 0 Then
Dim match As Object
For Each match In matches
Dim abbrev As String
abbrev = match.Value
If InStr(txtBox.TextFrame.TextRange.text, abbrev) = 0 Then
If txtBox.TextFrame.TextRange.text <> "" Then
txtBox.TextFrame.TextRange.text = txtBox.TextFrame.TextRange.text & ", " & abbrev
Else
txtBox.TextFrame.TextRange.text = abbrev
End If
End If
Next match
End If
End If
Next node
End Sub