Arisify / yamlcomments

A PMMP virion pasting YAML comments
MIT License
3 stars 1 forks source link

Using regex to deal with comments #1

Open NTT1906 opened 2 years ago

NTT1906 commented 2 years ago

UTF-8?

~^\s*([\w\-_.]+)[ \t]*:([^\r\n#]+)([#\w\t ]*)~umx
NTT1906 commented 2 years ago

For all unicode

^\s*([^\r\n:]+)[ \t]*:([^\r\n#]+)([#\w\t ]*)
NTT1906 commented 2 years ago

https://3v4l.org/mTPP3 This but the return is silly

NTT1906 commented 2 years ago

This?

^\s*(\w+)\s*:.[^#]*\s*([\w\t ]*[^\r\n]*)
mine    :        carft j               ###     i漢字 H爨底下貔貅
tv: "tee" # HI
tvw: 9  #haha
9abaa: ahah #Hihia
#me

Rubular image

NTT1906 commented 2 years ago
^\s*((\w+)\s*:.[^\r\n#]*([^\r\n]*#*)?)?(#[^\r\n]*)*
mine    :        carft j               ###     i漢字 H爨
#底下貔貅
tv: "tee" # HI
tvw: 9  #haha
ah: shs
9abaa: ahah
#me

image image

NTT1906 commented 2 years ago

;-;

NTT1906 commented 2 years ago

https://3v4l.org/bRorV Like these results, we will use the 2, 3, 4 as those are the key, inline comment and next key doc.

This may have some more errors such as multilined doc? etc

NTT1906 commented 2 years ago

checked and that won't be a problem :'D

https://3v4l.org/bRorV Like these results, we will use the 2, 3, 4 as those are the key, inline comment and next key doc.

This may have some more errors such as multilined doc? etc

NTT1906 commented 2 years ago

checked and that won't be a problem :'D

https://3v4l.org/bRorV Like these results, we will use the 2, 3, 4 as those are the key, inline comment and next key doc. This may have some more errors such as multilined doc? etc

multilined doc with line between them won't connect...

NTT1906 commented 2 years ago
^\s*(?:(\w+)\s*:.[^\r\n#]*([^\r\n]*#*)?)?(#[^\r\n]*)*

https://3v4l.org/bRorV Like these results, we will use the 2, 3, 4 as those are the key, inline comment and next key doc.

This may have some more errors such as multilined doc? etc

This will use 1,2,3

NTT1906 commented 2 years ago

https://3v4l.org/tIeF9

^\s*(?:(\w+)\s*:.[^\r\n#]*([^\r\n]*#*)?)?(#[^\r\n]*)*

https://3v4l.org/bRorV Like these results, we will use the 2, 3, 4 as those are the key, inline comment and next key doc. This may have some more errors such as multilined doc? etc

This will use 1,2,3

NTT1906 commented 2 years ago
^\s*(?:(\w+)\s*:.[^\r\n#]*([^\r\n]*#*)?)?(#*(?:[^\r\n]|[\r\n]#)*)

image image

NTT1906 commented 2 years ago

image

NTT1906 commented 2 years ago

https://3v4l.org/T3Ov8

NTT1906 commented 2 years ago

https://3v4l.org/T3Ov8

This worked, however it still needs to refine the matches so that they don't split apart the documents. Another issue is the array dash, which I still don't know how to deal with... (Another capture group?):c

NTT1906 commented 2 years ago

https://3v4l.org/KYoCe

NTT1906 commented 2 years ago

This currently only parse for YAML 1.1 and not supporting that dash thingy

NTT1906 commented 2 years ago

Maybe I should split out the string by PHP then use smaller regex patterns for dealing with comments?

NTT1906 commented 2 years ago

https://3v4l.org/2SU5b

NTT1906 commented 2 years ago

https://rubular.com/r/KZnoRETGnAs1fv

NTT1906 commented 2 years ago

https://rubular.com/r/6BbAXGOQTwAIPo

NTT1906 commented 2 years ago

https://rubular.com/r/6BbAXGOQTwAIPo

https://3v4l.org/66Ylo

NTT1906 commented 2 years ago

https://3v4l.org/J1r4o

NTT1906 commented 2 years ago

i gave up :c