Replaceing using wildcard.



  • Howdy,

    Hope I can phrase this proper.
    I am trying to strip all the extraneous (relatively speaking) info from VRML files to generate component cut lists from my design software (not a cad program).

    so in any given file there will be lines like;
    translation 460.117 183.375 -220.966
    where “Translation” is a reoccurring tag, but the numbers that follow are variable.

    I am trying to discern a way to quickly search/replace these lines. In my brain it looks something like plugging “Translation*.*” into the search field (yeah, that doesn’t work). NP++ looks purdy darn robust, and I’m hoping there someone here who knows of a way to do this.

    Thanks for your time & attention.
    -Z-



  • This may not completely meet your requirement, because I don’t fully understand.
    Choose Regular expression in the search window and do the search or replace.
    Find:translation \d{3}\.\d{3} \d{3}\.\d{3} -\d{3}\.\d{3}
    Here is Regex syntax.

    PS:
    You should really explain your demand clearly. It’s a good idea to show us some examples.
    If you wanna find each line that starts with translation, then the expresion can be even easier:
    Find:^translation.* will select the whole line.



  • Howdy 古旮,

    Thanks for the super-fast response. Apologies for my lack of clarity, I was trying to be concise without providing too much information. Let me try to clarify.

    I have a background in art, I spent 10 years making 2d & 3d art for the entertainment industry, now I build furniture and artifacts, mostly from wood. I design my projects in 3DS (as I said, not a CAD program) because I am very proficient with the soft, and it does what I need it to do, most of the time. The one thing it doesn’t do is export a list of objects in the project file (called “Scene”).

    To this point my process for extracting a cutlist (for actual fabrication of material components) has been to include pertinent information in the naming of the various objects (such as Length, Width, thickness, radius, angle, etc.) Then I use a “select from list” function to acquire a screen grab (this usually takes several iterations because the screen is only so tall, and the lists can be long), Then I use a paint program to “stitch” these captures together vertically, and runt them through an OCR to get a text file, clean up the conversion artifacts in Notepad, and inset pipes ( | ) where I want delineations to occur when I bring it into a spread sheet for organizing and double checking for things like erroneous duplicates. This process has much to be desired, mainly in time spent between design and execution.

    To this date (and I’ve been looking for a better method for several years now) the ONLY other way to get a list of objects is to export a VRML file, which is inundated with (for my needs) superfluous lines of data. I am hoping that NP++ can help me to strip those lines out very quickly.

    So for example, I’ve designed an expansion for my shop space. As you can imaging, there are a large amount of objects in the scene (dimensional lumber for walls, floors, ceilings, etc.) here is an excerpt of two objects from the scene after I’ve exported it to VRML format( NUM) added in for refrencing);

    1. DEF Group___attic_walls Transform {
    2. translation 460.117 183.375 -220.966
    3. children [
    4. DEF Stud___2X4X94_75___286 Transform {
    5. translation 67.5001 -47.375 -60.875
    6. children [
    7. Transform {
    8. translation 0 47.375 0
    9. children [
    10. Shape {
    11. appearance Appearance {
    12. material Material {
    13. diffuseColor 0.341176 0.882353 0.560784
    14. }
    15. }
    16. geometry Box { size 5.5 94.75 1.5 }
    17. }
    18. ] }
    19. ]
    20. },
    21. DEF Rafter_Plate___2X4X49_75___05 Transform {
    22. translation 67.5001 -0.991302 83.1821
    23. rotation 1 0 0 -0.392699
    24. children [
    25. Shape {
    26. appearance Appearance {
    27. material Material {
    28. diffuseColor 0.341176 0.882353 0.560784
    29. }
    30. }
    31. geometry DEF Rafter_Plate___2X4X49_75___05-FACES IndexedFaceSet {
    32. ccw TRUE
    33. solid TRUE
    34. convex TRUE
    35. coord DEF Rafter_Plate___2X4X49_75___05-COORD Coordinate { point [
    36. -1.75 6.53281 0.75, 1.75 6.53281 0.75, -1.75 7.15413 -0.75,
    37. 1.75 7.15413 -0.75, -1.75 52.0407 0.75, 1.75 52.0407 0.75,
    38. -1.75 52.662 -0.75, 1.75 52.662 -0.75]
    39. }
    40. coordIndex [
    41. 0, 2, 3, 1, -1, 4, 5, 7, 6, -1, 0, 1, 5, 4, -1, 1,
    42. 3, 7, 5, -1, 3, 2, 6, 7, -1, 2, 0, 4, 6, -1]
    43. }
    44. }
    45. ]
    46. },

    I’ve included line 01) because “Groups” are important to me. They tell me what any given object is associated with, whether it’s a component of “Group___attic_walls” or, let’s say “Group__Stove Cabinet Upper”, or whatever. So I want to keep line 01).

    I don’t need line 02) or 03) really, so I’d (Ideally) just delete those two, and any other reoccurrence. Not a big deal for line 03), but line 02) has variables, and those usually change with every occurrence. This is why I want to “find/replace” with a wildcard. I want to find and replace every occurrence of line 03), including the variables with a pipe, or better yet, just rip it out completely.

    Line 04) is a component (3d object). In carpentry terms, “ DEF Stud___2X4X94_75___286 Transform {“ translates to; Stud#286 2”x4”x97.75”, A regular 2x4 straight cut 94.75” in length. In the design program, it is a parametric object that uses spinners to define it’s XYZ Dimensions. These dimensions are neatly defined for me in line 16). Before I talk about line 16, let me say that lines 05) thru 15) are not of value to me, so those get stripped out, sooner is always better than later in this endeavor.

    Back to line 16), This line tells me Stud#286 is a parametric object, so all I need to fabricate it is to get an 8’ long 2x4 and cut it down to 94.75”. Nice & simple. Yes the variables are off by a half inch, that is how they do it when they make dimensional lumber, a 2x4 is 1.5”x3.5” actual. I was never consulted on this. Lines 17) thru 20) are the “trailing ends” of Stud#286’s definition, they get ripped out.

    Line 21) starts the definition of Rafter Plate#05. I want to keep this line. Line 22) is not important, strip it. Line 23) is Rotation, I want to keep this line because though I haven’t figured out how yet, I know I can use this information to set up the miter saw to cut the proper angle on the ends of this board, I can solve that later. 24) thru 30) are not important, strip those out.

    Line 31) is of note because instead of reading “geometry Box”, it reads “geometry DEF” which tells me Rafter Plate#05 is not a parametric object, and shaping the component will involve miter cuts, notches, rounding, drilling/cutting holes in the board, or creating some sort of non-rectilinear shape. But this is not important enough to keep so strip this and lines 32) thru 34) while I’m at it.

    Line 35) is important because it is the start of a series of Cartesian coordinates that define the object in 3D space, I can use this to discern actual dimensions, and check for validity against the dimensions I defined when I named the object. Lines 36) thru 38) are the coordinates for every intersection of edges in the object, I want to keep those.

    Lines 39) thru 46) are unimportant, I rip those out.

    Alright, that is two objects in a scene of 917 objects total. This is a relatively large project, if I can get NP++ to help with the stripping, which is a major victory over time. I really hope this clarifies what I’m seeking to do, and doesn’t just dump a ton of confusion on the thread. I really appreciate any thoughts or wisdom you can impart. I’m going to investigate what you have shared so far and see if that will get me where I wanna go, or maybe give me some knowledge I can build on. If you (or anyone else for that matter) have any other info, please don’t hesitate to mention it.

    Thanks again for your time & attention.
    -Z-



  • Ah, ok!!! ^translation.* is working like a charm! TYSVVM, You totally rock!!!

    -Z-



  • Zoftan, this is a job for a regular expression and if you haven’t used them before it’s going to take a bit of work to get your head around them (it did for me and everyone else I have discussed it with.)

    Regular expressions or “regexes” are wildcards on steroids.

    For that pattern it would go something like this in search and replace:

    Search: ^\s*translation [-\d.\s]+$
    Replace:
    NOTHING if you wish to remove it.

    What is says is, Start at beginning of line ^, accept some spaces IF they are there, then Match that word literally and a space, then look for DASH DIGITS \d or DOT or WHITESPACE \s and match as many as you find + to the end of line $

    If you need to remove the blank line you can manage that too or use the NP++ comman (edit menu->line operatins) to remove them.

    You might have alter it a bit if there are trailing blanks (add \s+ before the $ sign).

    Of you might want to give a closer range of numbers: [-\d.]{10-26}
    This means find at least 10 of those characers (in the square brackets) and as many as 26.

    If you always want to kill the lines based on that first word you might use just this:
    Search: .Translaton.

    In regular expresion the “any character any number of times (including 0)” is DOT STAR ‘.*’
    DOT . means "any character and * means “zero or more of them”



  • Oh S W E E T! edit menu->line operatins is awesome!!! And thank you Herb as well for explaining DOT STAR (and the other items). At this time, the combination of ^translation.* and line operations is getting me through this at break neck speed.

    So, while I have some folks’ attention, I am now down to getting unwanted chunks that look like this;

               coordIndex [
                  20, 21, 22, 23, -1, 20, 23, 24, 39, -1, 31, 32, 
                  33, 30, -1, 30, 33, 34, 35, -1, 30, 35, 36, 
                  37, -1, 30, 37, 38, 39, -1, 29, 30, 39, 28, 
                  -1, 27, 28, 39, 26, -1, 25, 26, 39, 24, -1, 
                  10, 11, 21, 20, -1, 11, 12, 22, 21, -1, 12, 
                  13, 23, 22, -1, 13, 14, 24, 23, -1, 14, 15, 
                  25, 24, -1, 15, 16, 26, 25, -1, 16, 17, 27, 
                  26, -1, 17, 18, 28, 27, -1, 18, 19, 29, 28, 
                  -1, 19, 0, 30, 29, -1, 0, 1, 31, 30, -1, 1, 
                  2, 32, 31, -1, 2, 3, 33, 32, -1, 3, 4, 34, 
                  33, -1, 4, 5, 35, 34, -1, 5, 6, 36, 35, -1, 
                  6, 7, 37, 36, -1, 7, 8, 38, 37, -1, 8, 9, 39, 
                  38, -1, 9, 10, 20, 39, -1, 9, 8, 7, 11, -1, 
                  7, 6, 5, 3, -1, 5, 4, 3, -1, 3, 2, 1, 19, -1, 
                  1, 0, 19, -1, 19, 18, 17, 15, -1, 17, 16, 15, 
                  -1, 15, 14, 13, 11, -1, 13, 12, 11, -1, 19, 
                  15, 11, 3, -1, 7, 3, 11, -1, 10, 9, 11, -1]
    

    Sorry for the odd colors, it just did that when I pasted from NP++. Anyways, could I then modify what 古旮 said about using “translation \d{3}.\d{3} \d{3}.\d{3} -\d{3}.\d{3}” to something along the lines of " \d{*}+$" to strip the numbers, or might that also effect the other lines?

    Oh, one other small question. When I use “^translation.*”, it doesn’t actually work until I remove the ^. Is ^ supposed to signify something when folks that script & code are communicating w/ each other, or am I actually supposed to plug that into the field with my search criteria (if so, I wonder why it only works when I remove it.)?

    Thanks again Herb for the know, it was most juicy!
    -Z-



  • Hello, @zoltan-meszaros, and All,

    From your explanations, I build a regex S/R, which preserves the 9 lines 1, 4, 16, 21, 23, 35, 36, 37 and 38, of your example !

    So, given your example, below :

    DEF Group___attic_walls Transform {
    translation 460.117 183.375 -220.966
    children [
    DEF Stud___2X4X94_75___286 Transform {
    translation 67.5001 -47.375 -60.875
    children [
    Transform {
    translation 0 47.375 0
    children [
    Shape {
    appearance Appearance {
    material Material {
    diffuseColor 0.341176 0.882353 0.560784
    }
    }
    geometry Box { size 5.5 94.75 1.5 }
    }
    ] }
    ]
    },
    DEF Rafter_Plate___2X4X49_75___05 Transform {
    translation 67.5001 -0.991302 83.1821
    rotation 1 0 0 -0.392699
    children [
    Shape {
    appearance Appearance {
    material Material {
    diffuseColor 0.341176 0.882353 0.560784
    }
    }
    geometry DEF Rafter_Plate___2X4X49_75___05-FACES IndexedFaceSet {
    ccw TRUE
    solid TRUE
    convex TRUE
    coord DEF Rafter_Plate___2X4X49_75___05-COORD Coordinate { point [
    -1.75 6.53281 0.75, 1.75 6.53281 0.75, -1.75 7.15413 -0.75,
    1.75 7.15413 -0.75, -1.75 52.0407 0.75, 1.75 52.0407 0.75,
    -1.75 52.662 -0.75, 1.75 52.662 -0.75]
    }
    coordIndex [
    0, 2, 3, 1, -1, 4, 5, 7, 6, -1, 0, 1, 5, 4, -1, 1,
    3, 7, 5, -1, 3, 2, 6, 7, -1, 2, 0, 4, 6, -1]
    }
    }
    ]
    },
    
    • Copy your sample, in a new tab ( Ctrl + N )

    • Open the Replace dialog ( Ctrl + H )

    • Type in the regex (?s-i).*?(^((DEF)|geometry Box|rotation)[^\r\n]+\R|^coord DEF.+?]\R)|.* , in the Find what: zone

    • Type in the regex (?3\r\n)\1 , in the Replace with: zone

    • Set the Wrap around option

    • Set the Regular expression search mode

    • Click on the Replace All button

    Et voilà ! you should get the following text :

    DEF Group___attic_walls Transform {
    
    DEF Stud___2X4X94_75___286 Transform {
    geometry Box { size 5.5 94.75 1.5 }
    
    DEF Rafter_Plate___2X4X49_75___05 Transform {
    rotation 1 0 0 -0.392699
    coord DEF Rafter_Plate___2X4X49_75___05-COORD Coordinate { point [
    -1.75 6.53281 0.75, 1.75 6.53281 0.75, -1.75 7.15413 -0.75,
    1.75 7.15413 -0.75, -1.75 52.0407 0.75, 1.75 52.0407 0.75,
    -1.75 52.662 -0.75, 1.75 52.662 -0.75]
    

    In addition, this regex inserts a blank line, before each object :-))

    Of course, give a second try to my regex, with your “true” file. Probably, it will not be OK, at first time ;-)

    See you later,

    Best Regards,

    guy038

    P.S. :

    For noob people, about regular expressions concept and syntax, begin with that article, in N++ Wiki :

    http://docs.notepad-plus-plus.org/index.php/Regular_Expressions

    In addition, you’ll find good documentation, about the Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v5.8 ), used by Notepad++, since its 6.0 version, at the two addresses below :

    http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

    http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

    • The FIRST link explains the syntax, of regular expressions, in the SEARCH part

    • The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part


    You may, also, look for valuable information, on the sites, below :

    http://www.regular-expressions.info

    http://www.rexegg.com

    http://perldoc.perl.org/perlre.html

    Be aware that, as any documentation, it may contain some errors ! Anyway, if you detected one, that’s good news : you’re improving ;-))



  • Hello Zoltan Meszaros and Herb Martin,
    To Zoltan Meszaros:
    It seems you’ve come to use Notepad++ quite recently.

    You said:

    Anyways, could I then modify what 古旮 said about using “translation \d{3}.\d{3} \d{3}.\d{3} -\d{3}.\d{3}” to something along the lines of " \d{*}+$" to strip the numbers, or might that also effect the other lines?

    Sorry I don’t understand what you mean by “strip the numbers”. I believe a before-and-after of your demand will explain everything.

    About the ^ thing, please go into the Regular Expression Syntax first(which is also given in my last reply).
    Then search for anchor in the page. Then you’ll get the explanation for that syntax:

    A ‘^’ character shall match the start of a line.

    I added ^ so that the regex will match

    translation blablabla

    but will skip

    blablabla translation blablabla

    Actually, the most simple way to learn how to use regex is to search “regular expression syntax” in google. But I’d suggest you read the link I gave to you, because it is the exact regex engine that NPP is using.
    Just go through each syntax of that page. You can do some experiments if you don’t fully understand one.
    Some of them(like Recursive Expressions) may be too hard and useless, and you can skip. Most of them is OK, and I think you can learn well very quickly.

    To @Herb-Martin, and anyone who is new to this forum :
    Check out The Markdown Syntax of this forum.
    Use “`” instead of " as qoutation marks.



  • Howdy folks,

    Thanks guy038 and 古旮 for the info and reference links. I will be chewing on those for a good while, especially considering that the further I edit this thing, the more I want to automate the process thus the more I need to learn how to use expressions.

    Apologies for the response lag, internet was down for 5 days and when it came back up I was swarmed by emails. Sorry 古旮 also for the confusion, I write as I speak, and don’t always pay attention when I am using slang when composing a message. When I said “Strip the Numbers” I meant “remove that data from the file”.

    Folks, thank you all so very much for the guidance, examples, and references. I have a feeling I will be seeing this site again and again. Here’s hoping that Expressions are easier to teach myself than scripting. Peace out to y’all.

    -Z-


Log in to reply