@@ -278,31 +278,31 @@ describe Use-Regex {
278
278
279
279
context ' Special Piping Behavior' {
280
280
it ' Will match the contents if piped in a file' {
281
- (Get-Command Write -RegEx |
281
+ (Get-Command New -RegEx |
282
282
Select-Object - ExpandProperty ScriptBlock |
283
283
Select-Object - ExpandProperty File) -as [IO.FileInfo ] |
284
284
? < PowerShell_HelpField> |
285
285
Select-Object - ExpandProperty InputObject |
286
286
Select-Object - ExpandProperty Name |
287
- should - Be Write-Regex .ps1
287
+ should - Be New-RegEx .ps1
288
288
}
289
289
290
290
it ' Will match the script contents if passed an external script' {
291
- Get-Command ((Get-Command Write -RegEx |
291
+ Get-Command ((Get-Command New -RegEx |
292
292
Select-Object - ExpandProperty ScriptBlock |
293
293
Select-Object - ExpandProperty File)) |
294
294
? < PowerShell_HelpField> |
295
295
Select-Object - ExpandProperty InputObject |
296
296
Select-Object - ExpandProperty Name |
297
- should - Be Write-Regex .ps1
297
+ should - Be New-RegEx .ps1
298
298
}
299
299
300
300
it ' Will match the definition if passed a function' {
301
- Get-Command Write -RegEx |
301
+ Get-Command New -RegEx |
302
302
? < PowerShell_HelpField> |
303
303
Select-Object - ExpandProperty InputObject |
304
304
Select-Object - ExpandProperty Name |
305
- should - Be Write -RegEx
305
+ should - Be New -RegEx
306
306
}
307
307
}
308
308
@@ -353,62 +353,62 @@ describe Use-Regex {
353
353
}
354
354
355
355
356
- describe Write-Regex {
356
+ describe New-RegEx {
357
357
it " Helps you write -CharacterClasses" {
358
- Write -RegEx - CharacterClass LowerCaseLetter |
358
+ New -RegEx - CharacterClass LowerCaseLetter |
359
359
Select-Object - ExpandProperty Pattern |
360
360
should - Be ' \p{Ll}'
361
361
}
362
362
it " Lets you look for repeated content" {
363
- Write -RegEx - CharacterClass Digit - Repeat |
363
+ New -RegEx - CharacterClass Digit - Repeat |
364
364
Select-Object - ExpandProperty Pattern |
365
365
should - Be ' \d+'
366
366
}
367
367
368
368
369
369
370
370
it " Simplifies lookahead with -Before (aka -LookAhead)" {
371
- Write -RegEx - Expression ' q' - LookAhead u | # Matches a q that is followed by a u
371
+ New -RegEx - Expression ' q' - LookAhead u | # Matches a q that is followed by a u
372
372
Select-Object - ExpandProperty Pattern |
373
373
should - Be ' q(?=u)'
374
374
}
375
375
376
376
it ' Simplifies lookbehind with -After (aka -LookBehind)' {
377
- Write -RegEx - Expression u - LookBehind q | # Matches a u that is preceeded by a q
377
+ New -RegEx - Expression u - LookBehind q | # Matches a u that is preceeded by a q
378
378
Select-Object - ExpandProperty Pattern |
379
379
should - Be ' (?<=q)u'
380
380
}
381
381
382
382
it ' Simplifies negative lookahead with -NotBefore' {
383
- Write -RegEx - Expression q - NotBefore u | # Matches a q that isn't followed by a u
383
+ New -RegEx - Expression q - NotBefore u | # Matches a q that isn't followed by a u
384
384
Select-Object - ExpandProperty Pattern |
385
385
should - Be ' q(?!u)'
386
386
}
387
387
388
388
389
389
it " Simplifies negative lookbehind with -NotAfter (aka -NegativeLookBehind)" {
390
- Write -RegEx - Expression ' "' - NegativeLookBehind ' \\' |
390
+ New -RegEx - Expression ' "' - NegativeLookBehind ' \\' |
391
391
Select-Object - ExpandProperty Pattern |
392
392
should - Be ' (?<!\\)"'
393
393
}
394
394
it " Can pipe to itself to compound expressions" {
395
- Write -RegEx - Pattern ' "' |
396
- Write -RegEx - CharacterClass Any - Repeat - Lazy - Before (
397
- Write -RegEx - Pattern ' "' - NotAfter ' \\|`'
395
+ New -RegEx - Pattern ' "' |
396
+ New -RegEx - CharacterClass Any - Repeat - Lazy - Before (
397
+ New -RegEx - Pattern ' "' - NotAfter ' \\|`'
398
398
) |
399
- Write -RegEx - Pattern ' "' |
399
+ New -RegEx - Pattern ' "' |
400
400
Select-Object - ExpandProperty Pattern |
401
401
should - Be ' ".+?(?=(?<!\\|`)")"'
402
402
}
403
403
404
404
it ' Can combine more than on -CharacterClass' {
405
- Write -RegEx - CharacterClass Digit, Word |
405
+ New -RegEx - CharacterClass Digit, Word |
406
406
Select-Object - ExpandProperty Pattern |
407
407
should - Be ' [\d\w]'
408
408
}
409
409
410
410
it ' Can negate a -CharacterClass' {
411
- Write -RegEx - CharacterClass Digit, Word -Not |
411
+ New -RegEx - CharacterClass Digit, Word -Not |
412
412
Select-Object - ExpandProperty Pattern |
413
413
should - Be ' [^\d\w]'
414
414
}
@@ -420,126 +420,126 @@ describe Write-Regex {
420
420
}
421
421
422
422
it ' Can negate a -LiteralCharacter' {
423
- Write-Regex - LiteralCharacter ' .' -Not | Should - Be ' [^\.]'
423
+ New-RegEx - LiteralCharacter ' .' -Not | Should - Be ' [^\.]'
424
424
}
425
425
426
426
it ' Can use a -StartAnchor or -EndAnchor' {
427
- Write -RegEx - CharacterClass Whitespace - Min 0 - StartAnchor LineStart - EndAnchor LineEnd |
427
+ New -RegEx - CharacterClass Whitespace - Min 0 - StartAnchor LineStart - EndAnchor LineEnd |
428
428
Select-Object - ExpandProperty Pattern |
429
429
should - Be ' ^\s{0,}$'
430
430
}
431
431
432
432
it ' Can check for -Min and -Max occurances' {
433
- Write -RegEx - CharacterClass Whitespace - Min 0 - Max 4 |
433
+ New -RegEx - CharacterClass Whitespace - Min 0 - Max 4 |
434
434
Select-Object - ExpandProperty Pattern |
435
435
should - Be ' \s{0,4}'
436
436
}
437
437
438
438
it ' Can leave a comment' {
439
- Write -RegEx - CharacterClass Whitespace - Comment " Whitespace" |
439
+ New -RegEx - CharacterClass Whitespace - Comment " Whitespace" |
440
440
Select-Object - ExpandProperty Pattern |
441
441
should - BeLike " \s # Whitespace*"
442
442
}
443
443
444
444
it ' Can write a description' {
445
- Write -RegEx - CharacterClass Whitespace - Description " Whitespace" |
445
+ New -RegEx - CharacterClass Whitespace - Description " Whitespace" |
446
446
Select-Object - ExpandProperty Pattern |
447
447
should - Be " # Whitespace$ ( [Environment ]::NewLine) \s"
448
448
}
449
449
450
450
it ' Can name a capture' {
451
- Write -RegEx - Name Digits - CharacterClass Digit - Repeat |
451
+ New -RegEx - Name Digits - CharacterClass Digit - Repeat |
452
452
Select-Object - ExpandProperty Pattern |
453
453
should - Be ' (?<Digits>\d+)'
454
454
}
455
455
456
456
it ' Can write an expression that will always fail' {
457
- Write -RegEx -Not | select - ExpandProperty Pattern | should - Be ' (?!)'
457
+ New -RegEx -Not | select - ExpandProperty Pattern | should - Be ' (?!)'
458
458
}
459
459
460
460
it ' Can write an anti expression' {
461
- Write -RegEx -Not foo | Select-Object - ExpandProperty pattern | should - Be ' \A((?!(foo)).)*\Z'
461
+ New -RegEx -Not foo | Select-Object - ExpandProperty pattern | should - Be ' \A((?!(foo)).)*\Z'
462
462
}
463
463
464
464
it ' Can Be -Atomic' {
465
- Write -RegEx - Atomic - Pattern ' do' , ' die' -Or | select-object - expand Pattern | should - BeLike ' (?>*do*|*die*)'
465
+ New -RegEx - Atomic - Pattern ' do' , ' die' -Or | select-object - expand Pattern | should - BeLike ' (?>*do*|*die*)'
466
466
}
467
467
468
468
it ' Can Be -Greedy or -Lazy (or both)' {
469
- Write -RegEx - Pattern ' (.|\s)' - Greedy - Lazy | Select-Object - ExpandProperty Pattern | Should - Be ' (.|\s)*?'
469
+ New -RegEx - Pattern ' (.|\s)' - Greedy - Lazy | Select-Object - ExpandProperty Pattern | Should - Be ' (.|\s)*?'
470
470
}
471
471
472
472
it " Doesn't have to capture (with -NoCapture)" {
473
- Write -RegEx - NoCapture ' \d+' |
473
+ New -RegEx - NoCapture ' \d+' |
474
474
Select-Object - ExpandProperty Pattern | should - Be ' (?:\d+)'
475
475
}
476
476
477
477
it ' Can -Be optional' {
478
- Write -RegEx - Pattern do , die -Or - Optional | select-object - expand Pattern | should - BeLike ' (?:*do*|*die*)?'
478
+ New -RegEx - Pattern do , die -Or - Optional | select-object - expand Pattern | should - BeLike ' (?:*do*|*die*)?'
479
479
}
480
480
481
481
it ' Can use Saved Expressions (with the format ?<Name>)' {
482
- Write -RegEx ? < Digits> | Select-Object - ExpandProperty Pattern | should - BeLike ' *\d+*'
482
+ New -RegEx ? < Digits> | Select-Object - ExpandProperty Pattern | should - BeLike ' *\d+*'
483
483
}
484
484
485
485
it ' Can write conditionals' {
486
- Write -RegEx ' ((?<Digit>\d)|(?<NotDigit>\D))' - If Digit - Then ' \D' - Else ' \d' |
486
+ New -RegEx ' ((?<Digit>\d)|(?<NotDigit>\D))' - If Digit - Then ' \D' - Else ' \d' |
487
487
Use-RegEx - IsMatch ' a1' |
488
488
should - Be $true
489
- Write -RegEx ' (?<Digit>\d)' |
490
- Write -RegEx - If Digit - Then ' [abcdef]'
489
+ New -RegEx ' (?<Digit>\d)' |
490
+ New -RegEx - If Digit - Then ' [abcdef]'
491
491
}
492
492
493
493
it ' Can write backreferences' {
494
- Write -RegEx - Backreference previousCapture |
494
+ New -RegEx - Backreference previousCapture |
495
495
Select-Object - ExpandProperty Pattern |
496
496
Should - Be ' \k<previousCapture>'
497
497
498
- $ (Write -RegEx - Backreference 1 ).ToString() |
498
+ $ (New -RegEx - Backreference 1 ).ToString() |
499
499
Should - Be ' \1'
500
500
}
501
501
502
502
it ' Can refer to other saved captures in a pattern (by putting ?<CaptureName> without leading comments)' {
503
- Write -RegEx - Pattern ' ?<Digits>' |
503
+ New -RegEx - Pattern ' ?<Digits>' |
504
504
Use-RegEx - IsMatch -Match 1 |
505
505
should - Be true
506
506
}
507
507
508
508
it ' Can rename a saved capture (by putting (?<NewCaptureName>?<OldCaptureName>)' {
509
- Write -RegEx - Pattern ' (?<MyDigits>?<Digits>)' |
509
+ New -RegEx - Pattern ' (?<MyDigits>?<Digits>)' |
510
510
Use-RegEx - Extract -Match 1 |
511
511
Select-Object - ExpandProperty MyDigits |
512
512
should - Be 1
513
513
}
514
514
515
515
it ' Can match -Until a pattern' {
516
- $writeRegexCmd = $ExecutionContext.SessionState.InvokeCommand.GetCommand (' Write-Regex ' , ' Function' )
516
+ $writeRegexCmd = $ExecutionContext.SessionState.InvokeCommand.GetCommand (' New-RegEx ' , ' Function' )
517
517
518
- Write -RegEx - Pattern \< \# |
519
- Write -RegEx - Name Block - Until \#> |
520
- Write -RegEx - Pattern \#\> |
518
+ New -RegEx - Pattern \< \# |
519
+ New -RegEx - Name Block - Until \#> |
520
+ New -RegEx - Pattern \#\> |
521
521
Use-RegEx - Extract -Match $writeRegexCmd.Definition |
522
522
Select-Object - ExpandProperty Block |
523
- should - BeLike * Write-Regex *
523
+ should - BeLike * New-RegEx *
524
524
}
525
525
526
526
context ' -Between' {
527
527
it ' Makes it easy to match double quotes' {
528
- Write -RegEx - Between ' "' - Name InQuotes |
528
+ New -RegEx - Between ' "' - Name InQuotes |
529
529
Use-RegEx - Extract -Match ' this is not in quotes. "This Is \"". This is not in quotes' |
530
530
Select-Object - ExpandProperty InQuotes |
531
531
should - Be ' This Is \"'
532
532
}
533
533
534
534
it ' Makes it easy to match single quotes' {
535
- Write -RegEx - Between " '" - Name InQuotes - EscapeSequence " ''" |
535
+ New -RegEx - Between " '" - Name InQuotes - EscapeSequence " ''" |
536
536
Use-RegEx - Extract -Match " this is not in quotes. 'This Is '''. This is not in quotes" |
537
537
Select-Object - ExpandProperty InQuotes |
538
538
should - Be " This Is ''"
539
539
}
540
540
541
541
it ' Makes it easy to match block comments' {
542
- Write -RegEx - Name BlockComment - Between ' \<\#' , ' \#\>' - EscapeSequence ' ' |
542
+ New -RegEx - Name BlockComment - Between ' \<\#' , ' \#\>' - EscapeSequence ' ' |
543
543
Use-RegEx - Extract -Match @'
544
544
1 <#BlockComment#>
545
545
2
@@ -551,17 +551,17 @@ describe Write-Regex {
551
551
}
552
552
553
553
it ' Can Match a series of Digits up to a -DigitMax' {
554
- $r = Write -RegEx - DigitMax 16 - StartAnchor ' ^' - NotBefore ' \d'
554
+ $r = New -RegEx - DigitMax 16 - StartAnchor ' ^' - NotBefore ' \d'
555
555
$r.Match (" 16" ).Success | Should - Be $true
556
556
$r.Match (" 17" ).Success | Should - Be $false
557
557
}
558
558
559
559
it ' Can refer to a capture generator (parameters can -Be passed with () or {})' {
560
- Write -RegEx - Pattern ' ?<BalancedCode>{(}' |
560
+ New -RegEx - Pattern ' ?<BalancedCode>{(}' |
561
561
Use-RegEx - IsMatch -Match ' ({}' |
562
562
should - Be $false
563
563
564
- Write -RegEx - Pattern ' ?<BalancedCode>({)' |
564
+ New -RegEx - Pattern ' ?<BalancedCode>({)' |
565
565
Use-RegEx - IsMatch -Match ' ({}' |
566
566
should - Be $true
567
567
}
@@ -737,7 +737,7 @@ describe 'Generators' {
737
737
should - BeLike ' <#*#>'
738
738
}
739
739
it ' Will extract comments from a function' {
740
- Get-Command Write-Regex |
740
+ Get-Command New-RegEx |
741
741
? < MultilineComment> - Count 1 |
742
742
should - BeLike ' <#*#>'
743
743
}
@@ -767,11 +767,11 @@ describe Set-Regex {
767
767
(?<MathSymbol>\p{Sm})' - Description ' Using the special character class math' - Temporary
768
768
769
769
770
- Write -RegEx ' ?<MathSymbol>' | should - BeLike ' *\p{Sm}*'
770
+ New -RegEx ' ?<MathSymbol>' | should - BeLike ' *\p{Sm}*'
771
771
}
772
772
773
- it ' Can accept the output of Write-Regex ' {
774
- Write -RegEx - LiteralCharacter := - Name ColonOrEquals |
773
+ it ' Can accept the output of New-RegEx ' {
774
+ New -RegEx - LiteralCharacter := - Name ColonOrEquals |
775
775
Set-Regex
776
776
Get-Module Irregular |
777
777
Split-Path |
0 commit comments