Right regex expression to find out a string of characters

Hi there, I am looking for the right expression of regex to find the string of characters including upper and lower case letters and numbers with length of , say between 10 to 14, to be found anywhere on the file (any applicable type of files), even if it starts on one line and ends up on the next line. Also what it would be if I want to limit the letters and numbers by ignoring certain letters (upper or lower cases ) and digits. Any suggestion can be usefull.

Thanks to all you reply in advance :)

  • Can you tell us a bit more about the type of data / use case where you want to apply this RegEx?

    Are we talking about examining a data stream, text file contents (I'm thinking paragraphs of text?), a list of names?

    Something else?

    Normally, though I don't often use RegEx , I would use it for some kind of validation - typically in a field entered into an on-screen form (but that's just the nature of the work I do.)

  • Hi . Thanks for your reply. sure, i am trying to find a string of characters, as you guessed, as part of text file , althought if the file is binary i like to know if i can do some thing about it too. say i have a string like 12Had04Geod5q7 . So i want to know which files contain this string in my data base. the string might start with digit or upper case or lower case ... and the lenght also may vary .Although on the file (for example text file ) that code may strat at the end of one line , like (12Had) on one line and then the rest on the next line, so the regex expression should not take it as two strings one with 5 characters and other with 9. but recognize it as whole 14 characters string. As of the file kinds, it might be system file so no especial meaningful list of names and so, but can be opened by text file openers like "note" program. If you have any suggestion please bring it up. it definitly will be useful :) . Thanks again for your kind reply. 

  • Your request is a bit ambiguous, but a regex pattern of

    ^[a-zA-Z0-9\r\n]{10,14}$

    should match:

    abcdefghijklmno
    abcdefghijklmn (match)
    abcdefghij     (match)
    abcdefghi
    abcdefghijklm#
    abcdefg        (match with next line)
    hij
    klm

    This pattern assumes that you're using a case-insensitive match (e.g., PowerShell's -match operator and not not -cmatch.

  • Thought this might be a fun addition. Check out the ChatGPT answer to this question:

  • There is also a simple way to match a simple-known-pattern in any string in any text based file -

    get-content *.txt | select-string '12Had04Geod5q7' |  Select-Object filename,LineNumber,Line

    you can get as fancy as you'd like with select-string, where pattern follows standard matching rules or regex

    an example I use - it to find words in scripts that I want to re-use

    $ftypes = (".ini",".xml",".txt",".ps1",".psm1",".log")

    get-childitem  .\ -file |
       where {$_.extension -in $ftypes} | 
       Select-String -Pattern "edms|ldap" | 
       Select-Object filename,LineNumber,Line


    It will return some strings from some binaries - but it's a wee bit ugly.  Guessing not designed for that.