<RetVar/IF> match regular expression: <Var/String> to string <Var/String>

This forum serves as MSCI Reference at EGOSOFT. It's Read-Only for non MSCI Group members.

Moderators: Scripting / Modding Moderators, MSCI Moderators

Locked
mark_a_condren
Posts: 1468
Joined: Wed, 3. Aug 05, 05:05
x3tc

<RetVar/IF> match regular expression: <Var/String> to string <Var/String>

Post by mark_a_condren » Fri, 17. Sep 10, 13:31

[skip|else] if [not]|while [not]| <RetVar/IF> = match regular expression: <Var/String> to string <Var/String>


[skip|else] if [not]|while [not]| = The possible 'Conditional' statements that can be used with this command.
<RetVar/IF> = Command return, with an 'if' statement used it will be TRUE (1) if condition passes or FALSE (0) if it fails, orherwise if you use a Variable it will be TRUE / FALSE as an integer.
<Var/String> = The regular expression you wish to check for as a variable / string. This can be a variable containing a 'string' or a directly inputed 'string'.
<Var/String> = The variable / string you wish to check if it contains the required regular expression. This can be a variable containing a 'string' or a directly inputed 'string'.


The SE-command itself checks, if the pattern of the regular expression fits to the string:

Look at this to help understand regular expressions.


Example:

$regular.expression = '.ast'

$text = 'fast'
gosub check

$text = 'last'
gosub check

$text = 'nono'
gosub check

return null

check:

if match regular expression: $regular.expression to string $text
| $out = sprintf: fmt='%s matches.', $text, null, null, null, null
| write to player logbook $out
else
| $out = sprintf: fmt='%s doesn't match.', $text, null, null, null, null
| write to player logbook $out
end

endsub

Result:
The first two texts match, while the third doesn't.

Note:
When using this command in languages other than english, you may have problems with using the brackets [] or some of the other special characters. Unfortunatly the only possibility seems to be to either edit the xml-code directly or to use an external script editor, as the internal one can't handle these characters with the wrong keyboard-layout.


Command Location:
  • »» General Commands
    • »» Strings
      <RetVar/IF> = match regular expression: <Var/String> to string <Var/String>

User avatar
X2-Illuminatus
Moderator (Deutsch)
Moderator (Deutsch)
Posts: 24949
Joined: Sun, 2. Apr 06, 16:38
x4

[TiP][49] 287071

Post by X2-Illuminatus » Mon, 11. Oct 10, 16:28

[skip|else] if [not]|while [not]| <RetVar/IF> = match regular expression: <Var/String> to string <Var/String>


[skip|else] if [not]|while [not]| = Die möglichen bedingten Anweisungen, die mit diesem Befehl genutzt werden können.
<RetVar/IF> = Rückgabewert des Befehls, mit einer 'if' Anweisung wird dieser TRUE (1) (wahr) sein, wenn die Bedingung erfüllt ist oder FALSE (0) (falsch), wenn nicht. Andernfalls, wenn eine Variable genutzt wird, wird der Wert von TRUE / FALSE als ganze Zahl zurückgegeben.
<Var/String> = Der reguläre Ausdruck, den du überprüfen möchtest, als Variable / Zeichenkette. Dies kann entweder eine Variable, die eine Zeichenkette enthält, oder direkt eine Zeichenkette sein.
<Var/String> = Die Variable / Zeichenkette, bei der du überprüfen möchtest, ob sie den benötigten regulären Ausdruck enthält. Dies kann entweder eine Variable, die eine Zeichenkette enthält, oder direkt eine Zeichenkette sein.


Der SE-Befehl überprüft, ob das Muster des regulären Ausdrucks zur Zeichenkette passt.

Sieh dir diesen Artikel an, um reguläre Ausdrücke zu verstehen.


Beispiele:

$regular.expression = '.ast'

$text = 'fast'
gosub check

$text = 'last'
gosub check

$text = 'nono'
gosub check

return null

check:

if match regular expression: $regular.expression to string $text
| $out = sprintf: fmt='%s matches.', $text, null, null, null, null
| write to player logbook $out
else
| $out = sprintf: fmt='%s doesn't match.', $text, null, null, null, null
| write to player logbook $out
end

endsub

Ergebnis:
Die ersten beiden Texte passen, der dritte nicht.

Beachte:
Wenn du diesen Befehl in anderen Sprachen als Englisch benutzt, hast du möglicherweise Probleme mit Klammern [] oder anderen Sonderzeichen. Unglücklicherweise scheint die einzige Möglichkeit dies zu umgehen, das direkte Editieren des XML-Codes oder das Nutzen eines externen Script Editors zu sein.


Zu finden unter:
  • »» General Commands
    • »» Strings
      <RetVar/IF> = match regular expression: <Var/String> to string <Var/String>

Locked

Return to “MSCI Reference”