Mission Name in mission panel

Here is the mission name inside the yellow box.
image

The whole mission window text is stored into

missionName =
                                missionAgentWindow.uiNode
                                    |> EveOnline.ParseUserInterface.listDescendantsWithDisplayRegion
                                    |> List.filter (.uiNode >> .pythonObjectTypeName >> (==) "Edit")
                                    |> List.head
                                    |> Maybe.andThen (.uiNode >> .dictEntriesOfInterest >> Dict.get "_sr")

I am interested in this specific line:

<span id=subheader> (MISSION NAME HERE) </span>

I want to extract the mission name to store it.

Here is my regex that should work but maybe elm regex has limitation that I am not aware of.

Regex.fromString "(?<=<span id=subheader>)(.*)(?=<\\Sspan)" |> Maybe.withDefault Regex.never

I cannot get the regex to extract it.

I spent way too long trying to figure out what is wrong. Any help could be greatly appreciated.

Here is the regex : regex101: build, test, and debug regex

1 Like

Yes, the regex functions have some problems. Regex works as a black box that does not work the same way in all environments. That is why you can see return values from regex functions differ between web browsers or Elm runtimes like botengine.
You can see another example of problems with regex at Hello and feature request - #6 by Viir

Following these observations, I removed usage of regex from the example app program codes, like here: Improve readability in the program code · Viir/bots@a03ce00 · GitHub

For your case, we can use simpler functions to extract the interesting portion from the string. Also, we already have a very similar function in the examples for EVE Online here:

That one parses the security status in the info panel
In that case, the string from the game client looked like this:

<hint='Security status'>0.9</hint></color><fontsize=12><fontsize=8> </fontsize>&lt;<fontsize=8>

You can reuse the same getSubstringBetweenXmlTagsAfterMarker function with a different marker:

getSubstringBetweenXmlTagsAfterMarker "id=subheade"

This function is enough to get the mission name out of your sample:

And here is a copy of the getSubstringBetweenXmlTagsAfterMarker from the linked program code:

getSubstringBetweenXmlTagsAfterMarker : String -> String -> Maybe String  
getSubstringBetweenXmlTagsAfterMarker marker =
    String.split marker
        >> List.drop 1
        >> List.head
        >> Maybe.andThen (String.split ">" >> List.drop 1 >> List.head)
        >> Maybe.andThen (String.split "<" >> List.head)

You can paste the code into Elm Interactive to quickly test it on any input string:

let
  getSubstringBetweenXmlTagsAfterMarker : String -> String -> Maybe String  
  getSubstringBetweenXmlTagsAfterMarker marker =
    String.split marker
        >> List.drop 1
        >> List.head
        >> Maybe.andThen (String.split ">" >> List.drop 1 >> List.head)
        >> Maybe.andThen (String.split "<" >> List.head)

in
"<span id=subheader> (MISSION NAME HERE) </span>"
|> getSubstringBetweenXmlTagsAfterMarker "id=subheade"

Thanks for the tip. I didn’t realize there were tools already provided for these cases.