Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

regex match specific word is


export const getValue = (argv: string[], type: string): string => {
  switch (type) {
    case 'dir':
      const dir: string[] | null = argv.join(' ').match(/(--cwd).*/gi)
      return dir !== null
        ? dir
            .join(' ')
            .replace(/(s).*/gi, '')
            .split('=')[1]
            .replace(/.*(')/gi, '')
        : 'default'

    case 'file':
      const file: string[] | null = argv.join(' ').match(/[a-z/*]+.*(js|cjs|mjs|ts)/gi)
      return file !== null ? file[0] : 'default.js'

    default:
      throw new NyelemError('Get value type not exist')
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #regex #match #specific #word
ADD COMMENT
Topic
Name
3+5 =