Regex is working on Regex101 but not inside Powershell -
i have text file:
[tabs] mailboxsend=1 mailbox=8 users=6 documents_q=9 med_webservcalls_loa=3 fclmna=1 inczoomform=1 usersb=1 usersb_one=1 datapriv=1 med_webservcalls=2 tinvoices=1 porders=9 porderstotal=1 logpart=1 logcounters=1 partmsg=1 [external mail] send=y hostname=server domain=domain myemail=my@email.com myname=my test port=25 ssl=0 [search] suppliers=5,1 startbutton=1 ignore case=0 part=6,1
i'm trying capture text between [external mail]
next []
brackets group,
i have regex job , tested in regex101, after testing's found it's not working inside powershell:
$text = get-content c:\text.txt $text -match '(?s)(?<=\[external mail\]).*?(?=\[.*?\])' or: $text | select-string '(?s)(?<=\[external mail\]).*?(?=\[.*?\])'
nothing return
do have idea i'm missing?
thanks
since trying multiline regex match need working against single multiline string. difference between 2 cases of regex101 , powershell. get-content
returning string array. regex not matching doing test on single lines within file.
powershell 2.0
$text = get-content c:\text.txt | out-string
powershell 3.0 of higher
$text = get-content c:\text.txt -raw
as said in comments don't need regex, in way, type of string extraction. there scripts exist parse ini content. if intend replacing content have find partner cmdlet out-inicontent
assuming exists sure made it. vonpryz's answer contains more information on cmdlet
Comments
Post a Comment