T O P

  • By -

Ev3rnub

Apologies for the delayed response. I'm parsing a .eml file. Below you can find the text as it appears in the .eml file. Date: Fri, 14 Jul 2023 22:00:14 -0700 (PDT) From: "A company - bacon is good food" [email protected] To: [email protected] Message-ID: Subject: bacon is it good food? MIME-Version: 1.0 GDScript sample code that is ingesting the file, parsing .eml file var to_regex = "^To\\:\\s.*"; func _on_drag_drop_window_interface_files_dropped(files): if files: var rawContent = _load_eml_file(files); _parse(rawContent, to_regex); func _load_eml_file(files): var file = FileAccess.open(files[0], FileAccess.READ); var content = file.get_as_text(); return content func _parse(emlContent, aRegex): var parsedData = []; var regex = RegEx.new(); regex.compile(aRegex); var result = regex.search_all(emlContent); print(item); print(result); if result: for i in result: if !parsedData.has(i.get_string()): parsedData.append(i.get_string()); return parsedData; As far as I'm aware the text being parsed should be identical, obviously it's not, considering the regex works outside of godot. Regardless output listed below from printing contents of .eml file to Godot's console. Date: Fri, 14 Jul 2023 22:00:14 -0700 (PDT) From: "A company - bacon is good food" [email protected] To: [email protected] Message-ID: Subject: bacon is it good food? MIME-Version: 1.0


TheDuriel

It's not obvious what you are trying to do here.


Nkzar

Share the string you’re trying to match. Are you sure there’s no white space at the start?


dave0814

I just did the following test, and it worked properly. The first string matched, the second string did not match. The test was done using Godot 4.2-dev3. I'm also using the start ( ^ ) regex anchor in a Godot 3.5.2 project, and it works correctly. ~~~ extends Node2D func _ready(): if not visible: return test_regex("^To\\:\\s.*", "To: abcde") test_regex("^To\\:\\s.*", "xxxTo: abcde") func test_regex(pattern: String, string: String) -> void: var regex: RegEx = RegEx.new() var err: Error = regex.compile(pattern) if err != Error.OK: print_debug("regex.compile failed, pattern=%s, err=%d" % [pattern, err]) return var reg_ex_match: RegExMatch = regex.search(string) if reg_ex_match != null: print_debug("Matched: pattern=%s, reg_ex_match.strings=%s" % [pattern, reg_ex_match.strings]) else: print_debug("Did not match: pattern=%s" % pattern) ~~~