Regular Expressions 101

Community Patterns

22

Get path from any text

Created·2023-01-31 14:38
Updated·2023-07-23 20:17
Flavor·PCRE2 (PHP)
Recommended·
Get path (windows style) from any type of text (error message, e-mail corps ...), quoted or not. THIS IS THE SINGLE LINE VERSION ! If you want understand how it work or edit it, go https://regex101.com/r/7o2fyy Relative path are not supported The goal is to catch what "Look like" a path. See the limitations UNC path and prefix path like //./], [//?/] or [//./UNC/] are allowed some url path like [file:///C:/] or [file://] are allowed Catch path quoted with ["] and [']. But these quotes are include with the catch Quoted path is not concerned by limitations Limitations : (only unquoted path) [dot] and [space] is allowed, but not in a row [dot+space] or [space+dot at end of file name isn't catched INSIDE A NAME FILE (or last directory if it is a path to a directory) : [comma] is not supported (it stop the catch) after a first [dot], any [space] stop the catch after a [space], catch is stoped if next character is not a [letter], [digit] or [-] so, double [space] stop the catch Compatibility compatible PCRE, PCRE2 AutoHotkey : don't forget to escape "%" in "`%" /!\ Powershell and .Net /!\\ : this regex need some modification to be interpreted by powershell. You have to replace each (?&CapturGroupName) by \k. Use this powershell code to do this replacement : ` $powershellRegex = @' [Put here the regex to replace (?&CapturGroupName) with \k] '@ -replace '\(\?&(\w+)\)', '\k' ` This example code must return : [Put here the regex to replace \k with \k]
Submitted by nitrateag

Community Library Entry

0

Regular Expression
Created·2018-09-10 20:01
Flavor·PCRE (Legacy)

/
(?<cdrRecordType>d+)\,(?<globalCallID_callManagerId>d+)\,(?<globalCallID_callId>d+)\,(?<origLegCallIdentifier>d+)\,(?<dateTimeOrigination>d+)\,(?<origNodeId>d+)\,(?<origSpan>d+)\,(?<origIpAddr>d+)\,(?<callingPartyNumber>d+)\,(?<callingPartyUnicodeLoginUserID>d+)\,(?<origCause_location>d+)\,(?<origCause_value>d+)\,(?<origPrecedenceLevel>d+)\,(?<origMediaTransportAddress_IP>d+)\,(?<origMediaTransportAddress_Port>d+)\,(?<origMediaCap_payloadCapability>d+)\,(?<origMediaCap_maxFramesPerPacket>d+)\,(?<origMediaCap_g723BitRate>d+)\,(?<origVideoCap_Codec>d+)\,(?<origVideoCap_Bandwidth>d+)\,(?<origVideoCap_Resolution>d+)\,(?<origVideoTransportAddress_IP>d+)\,(?<origVideoTransportAddress_Port>d+)\,(?<origRSVPAudioStat>d+)\,(?<origRSVPVideoStat>d+)\,(?<destLegIdentifier>d+)\,(?<destNodeId>d+)\,(?<destSpan>d+)\,(?<destIpAddr>d+)\,(?<originalCalledPartyNumber>d+)\,(?<finalCalledPartyNumber>d+)\,(?<finalCallPartyUnicodeLoginUserID>d+)\,(?<destCause_location>d+)\,(?<destCause_value>d+)\,(?<destPrecedenceLevel>d+)\,(?<destMediaTransportAddress_IP>d+)\,(?<destMediaTransportAddress_Port>d+)\,(?<destMediaCap_payloadCapability>d+)\,(?<destMediaCap_maxFramesPerPacket>d+)\,(?<destMediaCap_g723BitRate>d+)\,(?<destVideoCap_Codec>d+)\,(?<destVideoCap_Bandwidth>d+)\,(?<destVideoCap_Resolution>d+)\,(?<destVideoTransportAddress_IP>d+)\,(?<destVideoTransportAddress_Port>d+)\,(?<destRSVPAudioStat>d+)\,(?<destRSVPVideoStat>d+)\,(?<dateTimeConnect>d+)\,(?<dateTimeDisconnect>d+)\,(?<lastRedirectDn>d+)\,(?<pkid>d+)\,(?<originalCallPartyNumberPartition>d+)\,(?<callingPartyNumberPartition>d+)\,(?<finalCalledPartyNumberPartition>d+)\,(?<lastRedirectDnPartition>d+)\,(?<duration>d+)\,(?<origDeviceName>d+)\,(?<destDeviceName>d+)\,(?<origCallTerminationOnBehalfOf>d+)\,(?<destCallTerminationOnBehalfOf>d+)\,(?<origCallPartyRedirectOnBehalfOf>d+)\,(?<lastRedirectRedirectOnBehalfOf>d+)\,(?<origCalledPartyRedirectReason>d+)\,(?<lastRedirectRedirectReason>d+)\,(?<destConversationId>d+)\,(?<globalCallId_ClusterID>d+)\,(?<joinOnBehalfOf>d+)\,(?<comment>d+)\,(?<authCodeDescription>d+)\,(?<authorizationLevel>d+)\,(?<clientMatterCode>d+)\,(?<origDTMFMethod>d+)\,(?<destDTMFMethod>d+)\,(?<callSecuredStatus>d+)\,(?<origConversationId>d+)\,(?<origMediaCap_Bandwidth>d+)\,(?<destMediaCap_Bandwidth>d+)\,(?<authorizationCodeValue>d+)\,(?<outpulsedCallingPartyNumber>d+)\,(?<outpulsedCalledPartyNumber>d+)\,(?<origIpv4v6Addr>d+)\,(?<destIpv4v6Addr>d+)\,(?<origVideoCap_Codec_Channel2>d+)\,(?<origVideoCap_Bandwidth_Channel2>d+)\,(?<origVideoCap_Resolution_Channel2>d+)\,(?<origVideoTransAdd_IP_Channel2>d+)\,(?<origVideoTransAdd_Port_Channel2>d+)\,(?<origVideoChannel_Role_Channel2>d+)\,(?<destVideoCap_Codec_Channel2>d+)\,(?<destVideoCap_Bandwidth_Channel2>d+)\,(?<destVideoCap_Resolution_Channel2>d+)\,(?<destVideoTransAdd_IP_Channel2>d+)\,(?<destVideoTransAdd_Port_Channel2>d+)\,(?<destVideoChannel_Role_Channel2>d+)\,(?<IncomingProtocolID>d+)\,(?<IncomingProtocolCallRef>d+)\,(?<OutgoingProtocolID>d+)\,(?<OutgoingProtocolCallRef>d+)\,(?<currentRoutingReason>d+)\,(?<origRoutingReason>d+)\,(?<lastRedirectingRoutingReason>d+)\,(?<huntPilotPartition>d+)\,(?<huntPilotDN>d+)\,(?<calledPartyPatternUsage>d+)\,(?<IncomingICID>d+)\,(?<IncomingOrigIOI>d+)\,(?<IncomingTermIOI>d+)\,(?<OutgoingICID>d+)\,(?<OutgoingOrigIOI>d+)\,(?<OutgoingTermIOI>d+)\,(?<outpulsedOrilCalledPartyNumber>d+)\,(?<outpulsedLastRedirectingNumber>d+)\,(?<wasCallQueued>d+)\,(?<totalWaitTimeInQueue>d+)\,(?<callingPartyNumber_uri>d+)\,(?<originalCalledPartyNumber_uri>d+)\,(?<finalCalledPartyNumber_uri>d+)\,(?<lastRedirectDn_uri>d+)\,(?<mobileCallingPartyNumber>d+)\,(?<finalMobileCalledPartyNumber>d+)\,(?<origMobileDeviceName>d+)\,(?<destMobileDeviceName>d+)\,(?<origMobileCallDuration>d+)\,(?<destMobileCallDuration>d+)\,(?<mobileCallType>d+)\,(?<originalCalledPartyPattern>d+)\,(?<finalCalledPartyPattern>d+)\,(?<lastRedirectingPartyPattern>d+)\,(?<huntPilotPattern>d+)\,
/
m
Open regex in editor

Description

no description available

Submitted by anonymous