Jump to content
Sign in to follow this  
Zoreal

StringRegExp - Match }

Recommended Posts

Zoreal

Hello,

I'm having some issue matching my string.

StringRegExp($MatchArray[$u],'channel":(.*)}',3)

The string looks like this...

blahblah..."channel":2}

I'm attempting to get the contents between the : and }

Thank you for any help!

Z

Share this post


Link to post
Share on other sites
UEZ

You mean the number. Try this

StringRegExp($MatchArray[$u], '.*":(d+)}', 3)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Melba23

Zoreal,

Flag 3 with StringRegExp returns an array - so you need to access its elements: ;)

$sText = 'blahblah..."channel":2}'

$aRet = StringRegExp($sText,'channel":(.*)}',3)

MsgBox(0, "Return", $aRet[0])

Personally I would use StringRegExpReplace to get the string directly: ;)

$sText = 'blahblah..."channel":2}'

$sRet = StringRegExpReplace($sText,'.*channel":(.*)}', "$1")

MsgBox(0, "Return", $sRet)

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Zoreal

You mean the number. Try this

StringRegExp($MatchArray[$u], '.*":(d+)}', 3)

Br,

UEZ

Well, in the sample I gave... I'm trying to grab the number 2. It won't necessarily be a number though. :wacko:

Also, I did try the d suggestion - It also failed to get the 2 out.

Edited by Zoreal

Share this post


Link to post
Share on other sites
Zoreal

Zoreal,

Flag 3 with StringRegExp returns an array - so you need to access its elements: ;)

$sText = 'blahblah..."channel":2}'

$aRet = StringRegExp($sText,'channel":(.*)}',3)

MsgBox(0, "Return", $aRet[0])

Personally I would use StringRegExpReplace to get the string directly: ;)

$sText = 'blahblah..."channel":2}'

$sRet = StringRegExpReplace($sText,'.*channel":(.*)}', "$1")

MsgBox(0, "Return", $sRet)

All clear? :)

M23

I'm using the StringRegExp to extract 1 piece - Given the dataset I'm using it on, it cannot return more the 1 value. Therefore...I'm using it as something like

$String = $SomeOtherVarsBeingPlacedHere & Chr(9) & _ArrayToString(StringRegExp($MatchArray[$u],'channel":(d*)}',3))

All I need is for the StringRegExp to return its $Array[0]=2

Edited by Zoreal

Share this post


Link to post
Share on other sites
UEZ

As Melba suggested you can use StringRegExpReplace() to strip out the information you need!

$String = $SomeOtherVarsBeingPlacedHere & Chr(9) & StringRegExpReplace($MatchArray[$u],'.*channel":(.*)}', "$1")

d means any digit (0-9) and if it is not a number then using d makes no sense.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Melba23

Zoreal,

StringRegExp will either return True/False or an array depending on the flag - you cannot get the matched group directly. That is why I would go for the StringRegExpReplace option. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Zoreal

Zoreal,

Flag 3 with StringRegExp returns an array - so you need to access its elements: ;)

$sText = 'blahblah..."channel":2}'

$aRet = StringRegExp($sText,'channel":(.*)}',3)

MsgBox(0, "Return", $aRet[0])

Personally I would use StringRegExpReplace to get the string directly: ;)

$sText = 'blahblah..."channel":2}'

$sRet = StringRegExpReplace($sText,'.*channel":(.*)}', "$1")

MsgBox(0, "Return", $sRet)

All clear? :)

M23

I had a change in input for this - The string now exists sometimes in each of the forms below.

"stop":27426,"category":"Customer satisfaction","start":26606,"phrase":"poor customer service","confidence":23,"channel":2

"stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":2}]

Notice the '}]' sometimes is appended after the number...

How can I structure the StringRegExpReplace to match only the channel's value?

StringRegExpReplace($MatchArray[$u],'channel":(/d*?)}?','$1')

This is what I came up with - Not working though :(

Share this post


Link to post
Share on other sites
Melba23

Zoreal,

This works for me: :)

$sText_1 = '"stop":27426,"category":"Customer satisfaction","start":26606,"phrase":"poor customer service","confidence":23,"channel":27'
$sText_2 = '"stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":29}]'

$sExtract_1 = StringRegExpReplace($sText_1, '(?i).*channel":(d*)}?.*', "$1")
MsgBox(0, "String 1", $sText_1 & @CRLF & @CRLF & $sExtract_1)

$sExtract_2 = StringRegExpReplace($sText_2, '(?i).*channel":(d*)}?.*', "$1")
MsgBox(0, "String 2", $sText_2 & @CRLF & @CRLF & $sExtract_2)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
UEZ

Or this way:

#include <Array.au3>
$sText = '"stop":27426,"category":"Customer satisfaction","start":26606,"phrase":"poor customer service","confidence":23,"channel":27' & @CRLF & _
'"stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":29}]'

$aResult = StringRegExp($sText, '(?i)channel":(.*)b', 3)
_ArrayDisplay($aResult)

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
AZJIO

$test='"stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":2}]'
$pos=StringInStr($test, 'channel":')
$test=Number(StringTrimLeft($test, $pos+8))
MsgBox(0, 'Yes?', $test)

$test='"stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":2}]'
$test=StringRegExpReplace($test, '(?i).*?channel":(d+).*', '1')
MsgBox(0, 'Yes?', $test)
Edited by AZJIO

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×