Jump to content

Recommended Posts

Posted

say i have a list like

[14] John Steve IV
Steven John IX
John Victor VI

I am trying to trim everything down to the roman letters using stringregexp

The pattern here doesn't seem to work well with (John Victor VI) since they both start with V and returns a wrong group

"\[?.*?\]?\w*\s\w*?\s?(I.*|X.*|V.*)"
Posted

IF the strings always end with the roman numbers then you can do something like:

Local $aStrings[3] = ["[14] John Steve IV", "Steven John IX", "John Victor VI"]

For $i = 0 To UBound($aStrings)-1
    ConsoleWrite(StringTrimLeft($aStrings[$i], StringInStr($aStrings[$i], " ", 0, -1)) & @CRLF)
Next

..or if you're insisting to use StringRegExpReplace then you can do:

Local $aStrings[3] = ["[14] John Steve IV", "Steven John IX", "John Victor VI"]

For $i = 0 To UBound($aStrings)-1
    ConsoleWrite(StringRegExpReplace($aStrings[$i], ".*\s(.*)", "\1") & @CRLF)
Next
Posted (edited)

Or if you are looking for any Roman numeral:

StringRegExp ($sString, "(?:[^A-z]|\A)([I;V;X;C;D;M]+)(?:[^A-z]|\Z)", 3)
would work. It will only pick up what you want it to I think... And it's case sensitive.

Mat

Edit: But returns an array. I will modify now...

Edit2: Probably a bit more complicated than it needs to be but:

$sText = "[14] John Steve IV" & @CRLF & "Steven John IX" & @CRLF & "John Victor VI"

$sNew = StringRegExpReplace ($sText, "(?s)(.*?)(\W|\A)([IVXCDM]+)(\W|\Z)(.*?)", "\3" & @CRLF)

MsgBox (0, "Result", $sNew)
Edited by Mat
  • Moderators
Posted

Does this work?

Global $s_str = _
    "John Steve IV" & @CRLF & _
    "Steven John IX" & @CRLF & _
    "John Victor VI"
Global $s_pattern = "(.*?\W)([IVXLCDM]+)((?:\z|\W.*?))"
Global $s_out = StringRegExpReplace($s_str, $s_pattern, "$2")
ConsoleWrite($s_out & @CRLF)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...