Forum Discussion
RegExp Writing
Kindly elaborate the following Regular expression. How it will work?
(.)+.(xlsx|docx)
- murali_125469
Nimbostratus
Basically what its doing is its looking for anyname with .xlsx or .docx
() --> Groups multiple tokens together and creates a capture group for extracting a substring or using a backreference.
(.) -->Matches any character except line breaks + -->Matches 1 or more of the preceding token. | -->Acts like a boolean OR. Matches the expression before or after the |
If this helped , please mark as correct answer !
Thank You Murali
- Stanislas_Piro2
Cumulonimbus
Hi,
this expression will :
- match any string ending with either xlsx or docx
- store the first letter in the first match group
- store xlsx or docx in the second match group
if you want the character before xlsx or docx is a dot, the expression must be :
(.)+\.(xlsx|docx)
If you want to store the name without extension, and not the first character, the expression must be :
(.+)\.(xlsx|docx)
If you don't want to store name value in match group, remove parenthesis:
.+\.(xlsx|docx)
If you don't want to store extension in match group, add ?: after the opening parenthesis
.+\.(?:xlsx|docx)
you can play with this on online services like this one
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com