Posts

Showing posts from September, 2011

Can I Replace Groups In Java Regex?

Answer : Use $n (where n is a digit) to refer to captured subsequences in replaceFirst(...) . I'm assuming you wanted to replace the first group with the literal string "number" and the second group with the value of the first group. Pattern p = Pattern.compile("(\\d)(.*)(\\d)"); String input = "6 example input 4"; Matcher m = p.matcher(input); if (m.find()) { // replace first number with "number" and second number with the first String output = m.replaceFirst("number $3$1"); // number 46 } Consider (\D+) for the second group instead of (.*) . * is a greedy matcher, and will at first consume the last digit. The matcher will then have to backtrack when it realizes the final (\d) has nothing to match, before it can match to the final digit. You could use Matcher#start(group) and Matcher#end(group) to build a generic replacement method: public static String replaceGroup(String regex, String source, int groupT

Bootstrap 3 Navbar Horizontal Code Example

Example: bootstrap 3 menu < nav class = " navbar navbar-default " role = " navigation " > <!-- Brand and toggle get grouped for better mobile display --> < div class = " navbar-header " > < button type = " button " class = " navbar-toggle " data-toggle = " collapse " data-target = " #bs-example-navbar-collapse-1 " > < span class = " sr-only " > Toggle navigation </ span > < span class = " icon-bar " > </ span > < span class = " icon-bar " > </ span > < span class = " icon-bar " > </ span > </ button > < a class = " navbar-brand " href = " # " > Brand </ a > </ div > <!-- Collect the nav links, forms, and other content for toggling --> < div class = " collapse navbar-collapse

-nan(ind) C++ Code Example

Example: nan c++ example # include <iostream> # include <cmath> using namespace std ; // main() section int main ( ) { double nanValue ; //generating generic NaN value //by passing an empty string nanValue = nan ( "" ) ; //printing the value cout << "nanValue: " << nanValue << endl ; return 0 ; }

Bee Swarm Simulator Wiki Code Example

Example: Bee swarm simulator description [ To celebrate the first anniversary of Bee Swarm Sim, you can use the code "AnniversaBee" for 48 hours of x2 Pollen and Conversion Rate (this weekend only)! Sorry the update wasn't finished in time - it's almost there though and I expect to release it next weekend. You can use the code to save up honey for upcoming items. ] Grow your own swarm of bees, collect pollen, and make honey in Bee Swarm Simulator! Meet friendly bears, complete their quests and get rewards! As your hive grows larger and larger, you can explore further up the mountain. Use your bees to defeat dangerous bugs and monsters. Look for treasures hidden around the map. Discover new types of bees, all with their own traits and personalities! Join Bee Swarm Simulator Club for free Honey, Treats and Codes!: https://www.roblox.com/My/Groups.aspx?gid=3982592

Get 3d Vector Projection 2d Plane Code Example

Example: 3d projection onto 2d plane algorithm # include <vector> # include <cmath> # include <stdexcept> # include <algorithm> struct Vector { Vector ( ) : x ( 0 ) , y ( 0 ) , z ( 0 ) , w ( 1 ) { } Vector ( float a , float b , float c ) : x ( a ) , y ( b ) , z ( c ) , w ( 1 ) { } /* Assume proper operator overloads here, with vectors and scalars */ float Length ( ) const { return std :: sqrt ( x * x + y * y + z * z ) ; } Vector Unit ( ) const { const float epsilon = 1e-6 ; float mag = Length ( ) ; if ( mag < epsilon ) { std :: out_of_range e ( "" ) ; throw e ; } return * this / mag ; } } ; inline float Dot ( const Vector & v1 , const Vector & v2 ) { return v1 . x * v2 . x + v1 . y * v2 . y + v1 . z * v2 . z ; } class Matrix { public : Matr

Best Sword Enchantments Minecraft Command Code Example

Example: maxed diamond sword command /give @p diamond_sword{Enchantments:[{id:sharpness,lvl:5},{id:knockback,lvl:2},{id:fire_aspect,lvl:2},{id:looting,lvl:3},{id:sweeping,lvl:3},{id:unbreaking,lvl:3},{id:mending,lvl:1}]} 1

Android Studio Add Button Border Radius Code Example

Example: how to add corner radius in android button < shape xmlns: android = " http://schemas.android.com/apk/res/android " android: shape = " rectangle " > < solid android: color = " @color/primary " /> < corners android: radius = " 5dp " /> </ shape >

C++ Cout Does Not Name A Type Code Example

Example: cout does not name a type //Statements in C++ need to be inside of a function int main ( ) { std :: cout << "Hello World" << std :: endl ; //Works because we are inside of a function } std :: cout << "Hello World" << std :: endl ; //Doesn't work because we are not inside of a function

Camtasia 2020 Offline Activation Free Code Example

Example: camtasia 2020 offline activation UHGFS-WERTG-HJ6UY-GFDSE-RTYH9 FSW6Q-AZXDE-WQAZX-CVG7K-JNBVG

Can't Delete Font Files

Answer : This Registry key manages fonts that the system knows about: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts I discovered in an older answer that removing a value of that key or changing a value's data to point to a nonexistent file will make Windows not see the font as usable. Therefore, if you remove the Registry entries that correspond to the fonts you want to torch (and then restart to make the system reload everything), you should be able to delete the fonts' files. If the above does not work on Windows 10, you can also STOP and DISABLE the following two services: Windows Font Cache Service Windows Presentation Foundation Font Cache 3.0.0.0 Reboot your computer, delete the font files, and re-enable the services by setting the Startup Type back to 'Manual'.

Angular 4 Form Validators - MinLength & MaxLength Does Not Work On Field Type Number

Answer : Update 1 : phone: ['', [Validators.required, Validators.min(10000000000), Validators.max(999999999999)]], Used it like following and worked perfectly : phone: ['', [Validators.required, customValidationService.checkLimit(10000000000,999999999999)]], customValidationService : import { AbstractControl, ValidatorFn } from '@angular/forms'; export class customValidationService { static checkLimit(min: number, max: number): ValidatorFn { return (c: AbstractControl): { [key: string]: boolean } | null => { if (c.value && (isNaN(c.value) || c.value < min || c.value > max)) { return { 'range': true }; } return null; }; } } try this working sample code : component.html <div class="container"> <form [formGroup]="myForm" (ngFormSubmit)="registerUser(myForm.value)" novalidate> <div class="form-group"

AngularJS: Resolve In RouteProvider - Detecting Success / Failure?

Answer : You can just return the return value of the then method: resolve: { resolvedData: function(Restangular){ return Restangular.one('Items').get().then(function (data) { ... return successData; // resolvedData will be resolved with the successData }, function () { ... return failureData; // resolvedData will be resolved with the failureData }); } } The then method doc: This method returns a new promise which is resolved or rejected via the return value of the successCallback or errorCallback. If the resolve function fail, you will probably want to display to the user something accordingly (like an error message). It would be better to let your resolve function return a promise (without then ) and use the internal event $routeChangeError . myApp.run(['$rootScope',function($rootScope) { $rootScope.$on('$routeChangeError', function() { // what you w

Avl Tree Simulation Code Example

Example: avl tree c implementation # include <stdio.h> # include "avltree.h" /* remove all nodes of an AVL tree */ void dispose ( node * t ) { if ( t != NULL ) { dispose ( t -> left ) ; dispose ( t -> right ) ; free ( t ) ; } } /* find a specific node's key in the tree */ node * find ( int e , node * t ) { if ( t == NULL ) return NULL ; if ( e < t -> data ) return find ( e , t -> left ) ; else if ( e > t -> data ) return find ( e , t -> right ) ; else return t ; } /* find minimum node's key */ node * find_min ( node * t ) { if ( t == NULL ) return NULL ; else if ( t -> left == NULL ) return t ; else return find_min ( t -> left ) ; } /* find maximum node's key */ node * find_max ( node * t ) { if (